Ruby Pattern Get Started

Pattern for Pattern

Separate what it changes and what it doesn’t change
Make programs of interface, not implemented
Inheritance >> Aggregation
Delegation you do

Get Started

  • Inheritance
  • Aggregation
  • Delegation

Inheritance

Extends basic class

class Vehicle
   def start_engine
   end
   def stop_engine
   end
end

Add features

class Car < Vehicle
   def sunday_drive
      start_engine
      stop_engine
   end
end
&#91;/ruby&#93;

<h3>Aggregation</h3>
[ruby]
class Engine
   def start
   end
   def stop
   end
end

class Car
   def initialize
      @engine = Engine.new
   end
   def sunday_drive
      @engine.start
      @engine.stop
   end
end

Delegation

You did it! I ask you to do it!

class AKB
   def initialize
      @staff = Staff.new
   end
   def makeup
      @staff.makeup
   end
   def switch_to_super
      @staff = SuperStaff.new
   end
   def prepare
      @staff.prepare
   end
end
class Staff
  def makeup
  end
  def prepare
  end
end

Staff did all things