Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions Homeworks/behavioral_design_patterns/area.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Template method Design Pattern
# https://cacoo.com/diagrams/fnlz5bSWSRPtuoAF

class Area
def initialize *args ; end

def calculate ; end

def area
calculate()
end
end

class RectangularArea < Area
def initalize(longitude, width)
@longitude = longitude
@width = width
end

def calculate
(@longitude + @width) * 2
end
end

def SquareArea < Area
def initialize(edge)
@edge = edge
end

def calculate
(@edge * 4)
end
end

def CircleArea < Area
def initialize(radius)
@radius = radius
end

def calculate
(@radius * @radius * 2)
end
end
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions Homeworks/behavioral_design_patterns/transport_algorithm.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Strategy design pattern
# https://cacoo.com/diagrams/SYmlKFaYO7TY5ZiV
class TransportAlgorithm
def tranfer ;end
end

def TransportationToAirportByTaxi
def initialize(TransportAlgorithm transport_algorithm)
@transport_algorithm = transport_algorithm
end

def tranfer()
@transport_algorithm.tranfer()
end
end

def TransportToAirportByBus < TransportAlgorithm
def tranfer
# something code
end
end

class TransportationToAirport < TransportAlgorithm
def tranfer
# something code
end
end
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions Homeworks/creational_design_patterns/school_prototypes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#Design Patterns: Prototype

class SchoolPrototypes
def initialize *args; end

def clone
#code something
end
end


class TeamPrototypes < SchoolPrototypes
def clone
#code something
end
end

class GradePrototypes < SchoolPrototypes
def clone
#code something
end
end
Binary file added Homeworks/structural_design_patterns/Pay .png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
55 changes: 55 additions & 0 deletions Homeworks/structural_design_patterns/pay.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Old code
module PayAPI
def pay()
# your code here
end
end

class PayWithVietcomBank
include PayAPI
def start_pay()
# your code here
PayAPI.pay()
end
end

class PayWithVietinBank
include PayAPI
def start_pay()
# your code here
PayAPI.pay()
end
end

# Problem: If change name of pay method in PayAPI, you need change this name in all class use it
# Soluntion: Use adapter pattern
# Code refactored

module PayAPI
def pay()
# your code here
end
end

module CustomPayAPI
include PayAPI
def custom_pay()
PayAPI.pay()
end
end

class PayWithVietcomBank
include CustomPayAPI
def start_pay()
# your code here
CustomPayAPI.custom_pay()
end
end

class PayWithVietinBank
include CustomPayAPI
def start_pay()
# your code here
CustomPayAPI.custom_pay()
end
end