Patterns: By: Mohammad Kasif IMB2010024 IIIT-Alld
Patterns: By: Mohammad Kasif IMB2010024 IIIT-Alld
By:
Mohammad Kasif
IMB2010024
IIIT-Alld
Pattern:
A pattern is a well used, extremely
general solution to a common occurring
problem…
Eg:
o We have three classes, one representing a
Purchase Order, one for an Order line, and
finally, one for a SKU.
• The Expert pattern tells that the only class
who should be allowed to deal with the total
cost of purchase orders is the purchase
order class itself – because the class should
be an expert about all things to do with
purchase orders.
• Now to calculate the total of a purchase
order, the purchase order needs to find out
the value of all of the order lines.
Therefore the only class who should be
allowed to calculate the total of an order line
is the Order Line class itself.
• So we allocate a further behaviour to the
Order Line class. This method returns the
total cost of the single order line.
• To achieve this behaviour, the Order Line
class need to find out the cost of a single
SKU through another method in the SKU
class.
Creator Pattern…
• The Creator Pattern is a specific application
of the Expert Pattern.