Implementation Inheritance

  • warning: realpath() [function.realpath]: SAFE MODE Restriction in effect. The script whose uid is 1005 is not allowed to access /tmp owned by uid 0 in /var/www/sites/sugree/codenone.com/subdomains/www/html/includes/file.inc on line 190.
  • warning: realpath() [function.realpath]: SAFE MODE Restriction in effect. The script whose uid is 1005 is not allowed to access /tmp owned by uid 0 in /var/www/sites/sugree/codenone.com/subdomains/www/html/includes/file.inc on line 190.

มีข้อสงสัยเกี่ยว Ruby นิดหน่อยครับ

คืออยากทราบว่า Ruby สามารถ Implementation Inheritance แบบความสัมพันธ์ HAS-A ได้ไหมครับ

ขอบคุณมากครับ

มีตัวอย่างภาษาอื่นที่ทำได้เปล่าครับ?

ความสัมพันธ์แบบ HAS-A มันไม่น่าจะเรียกว่าเป็น inheritance นะครับ?

has-a ไม่ใช่ inheritance นี่ครับ? ..

แต่จริงๆ แล้วมันก็คงเป็นเหมือนกับว่า สร้างตัวแปรที่เอาไว้เก็บ reference ไปยัง object อีกอันหนึ่งก็เท่านั้นเองครับ อย่างเช่น

class Car
  attr_reader :steering_wheel
 
  def initialize(steering_wheel)
    @steering_wheel = steering_wheel
  end
 
  def start_engine
    # do something
  end
end
 
class SteeringWheel
  def turn_left
    # turn the car to the left
  end
 
  def turn_right
    # turn the car to the right
  end
end
 
a_car = Car.new(SteeringWheel.new)
a_car.start_engine
a_car.steering_wheel.turn_left
a_car.steering_wheel.turn_right

ย้าย Codenone

ประกาศย้าย Codenone ไปใช้ Forum ของ Blognone แทนครับ ตามไปตั้งกระทู้ต่อได้ที่ Codenone Forum (รายละเอียดอ่านจากกระทู้ ย้าย Codenone ไปรวมกับ Blognone)

กระทู้เก่าๆ จะย้ายตามไปในภายหลัง ตอนนี้ปิดการโพสต์กระทู้ไว้ เหลือไว้เฉพาะอ้างอิงเท่านั้น