class Patterns::Doctors

Doctors -> Object

Acts as a single object containing multiple other objects that it manages. (This is an example of the Component pattern, or Object Composition)

Attributes

doctors_list[RW]

The list of all of the doctors

general_practitioner[RW]

The general practitioner object

oncologist[RW]

The oncologist object

pediatrician[RW]

The pediatrician object

surgeon[RW]

The surgeon object

Public Class Methods

new() click to toggle source

Initializes the Doctors object and all of its members, then adds those members to the list.

# File app/models/chain_of_responsibility/doctors.rb, line 18
def initialize
  @doctors_list = []

  @surgeon = Surgeon.new
  @oncologist = Oncologist.new(surgeon)
  @general_practitioner = GeneralPractitioner.new(oncologist)
  @pediatrician = Pediatrician.new(general_practitioner)

  @doctors_list << @surgeon
  @doctors_list << @oncologist
  @doctors_list << @general_practitioner
  @doctors_list << @pediatrician
end

Public Instance Methods

see_patient(patient) click to toggle source

Starts the chain of responsibility by having the pediatrician see the first patient

# File app/models/chain_of_responsibility/doctors.rb, line 33
def see_patient(patient)
  @pediatrician.see_patient(patient)
end