class Car
attr_reader :steering_wheeldef initialize(steering_wheel)@steering_wheel = steering_wheel
enddef start_engine
# do somethingendendclass SteeringWheel
def turn_left
# turn the car to the leftenddef turn_right
# turn the car to the rightendend
a_car = Car.new(SteeringWheel.new)
a_car.start_engine
a_car.steering_wheel.turn_left
a_car.steering_wheel.turn_right
มีตัวอย่างภาษาอื่นที่ทำได้เปล่าครับ?
ความสัมพันธ์แบบ HAS-A มันไม่น่าจะเรียกว่าเป็น inheritance นะครับ?
has-a ไม่ใช่ inheritance นี่ครับ? ..
แต่จริงๆ แล้วมันก็คงเป็นเหมือนกับว่า สร้างตัวแปรที่เอาไว้เก็บ reference ไปยัง object อีกอันหนึ่งก็เท่านั้นเองครับ อย่างเช่น