Skip to content

Instantly share code, notes, and snippets.

@NAKKA-K
Created February 29, 2020 11:40
Show Gist options
  • Save NAKKA-K/f33929cd88aa618fabe8b3fa8855a11f to your computer and use it in GitHub Desktop.
Save NAKKA-K/f33929cd88aa618fabe8b3fa8855a11f to your computer and use it in GitHub Desktop.
class Trip
def initialize(machanic)
@machanic = machanic
end
def prepare
best_bicycles = @machanic.prepare_trip(self)
best_bicycles
end
private
def bicycles
bicycles = []
bicycles
end
end
class Machanic
def prepare_trip(trip)
bikes = trip.bicycles
prepare_bicycles(bikes)
end
private
# bicyclesの修理は外部から依頼される可能性があるならpublicに変える
def prepare_bicycles(bikes)
bikes.each do |bike|
# ...
end
end
end
# Machanicはprepare_tripというpublicインターフェース を持っていて、それを満たすものなら別のオブジェクトでも代替可能
machanic = Machanic.new
# Tripは「準備する」だけで最高の自転車も同時に用意してくれる
trip = Trip.new(machanic)
trip.prepare
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment