Design patterns Flashcards
(11 cards)
Abstract occurrence Pattern
Creating an occurrence class to represent individual things.
Context of AO pattern
Set of related objects which members share common info differing in big ways
Problem to solve with AO pattern
Need to duplicate objects without duplicating common info (eg duplicating data in customercontroller for oop)
Example scenario for AO pattern
Library multiple copies of the same book
Author, title etc the same, maybe id is different to distinguish, should we replicate objects?? NO
Solution to AO Pattern
Occurrence class.
One to many class between the abstraction and the occurrence
Abstraction class has all common elements
Occurrence class contains diff elements
Delegation pattern
Allows object composition ( a part of ) to achieve the same code reuse as inheritance.
How is this achieved?
An object handles a request by delegating it to a second object, the second object is a helper object to the original object
Why do this?
Composition is favourable over inheritance and has several advantages over inheritance.
Singleton Pattern
Only one instance of a class. Single point of access for the class
How to implement the singleton pattern?
- Static member containing instance of the class
- Private constructor where the single new instance is made
- Static public helper getter function to allow other objects to use this object
Why?
We use this pattern when we only want a single instance of the class to be created in our app ie loggers, db connectivity