Professional Documents
Culture Documents
1. Singelton : ......................................................................................... 2
1.1. Intro : ........................................................................................... 2
1.2. Structure: ..................................................................................... 2
1.3. Implementation: ........................................................................... 3
2. Composite : ....................................................................................... 3
2.1. Intro : ........................................................................................... 3
2.2. Structure : .................................................................................... 4
2.3. Implementation : .......................................................................... 5
2.4. Use cases : ................................................................................... 5
3. Observer : .......................................................................................... 6
3.1. Intro : ........................................................................................... 6
3.2. Structure : .................................................................................... 6
3.3. Implementation : .......................................................................... 7
3.4. Use cases: .................................................................................... 8
4. Strategy : ........................................................................................... 9
4.1. Intro : ........................................................................................... 9
4.2. Structure : .................................................................................... 9
4.3. Implementation : ........................................................................ 10
4.4. Use cases : ................................................................................. 10
5. MVC : ............................................................................................. 11
5.1. Intro : ......................................................................................... 11
5.1.1. Model : ................................................................................ 11
5.1.2. View : .................................................................................. 11
5.1.3. Controler : ........................................................................... 11
5.2. Structure .................................................................................... 11
Patrons de conception :
1. Singelton :
1.1. Intro :
This pattern involves a single class which is
responsible to create an object while making sure that only
single object which can be accessed directly without need
to instantiate the object of the class.
1.2. Structure:
2. Composite :
2.1. Intro :
The composite design pattern has a primary
goal of combining objects and classes into a
bigger structure while keeping the structure as
abstract as it possibly can be.
2.2. Structure :
3.3. Implementation :
Look over your business logic and try to break it
down into two parts: the core functionality,
independent from other code, will act as the
publisher; the rest will turn into a set of subscriber
classes.
Declare the subscriber interface. At a bare
minimum, it should declare a single update
method.
Declare the publisher interface and describe a pair
of methods for adding a subscriber object to and
removing it from the list. Remember that
publishers must work with subscribers only via
the subscriber interface.
Decide where to put the actual subscription list
and the implementation of subscription methods.
Usually, this code looks the same for all types of
publishers, so the obvious place to put it is in an
abstract class derived directly from the publisher
interface. Concrete publishers extend that class,
inheriting the subscription behavior.
- However, if you’re applying the pattern to an
existing class hierarchy, consider an approach
based on composition: put the subscription
logic into a separate object, and make all real
publishers use it.
Create concrete publisher classes. Each time
something important happens inside a publisher, it
must notify all its subscribers.
Implement the update notification methods in
concrete subscriber classes. Most subscribers
would need some context data about the event. It
can be passed as an argument of the notification
method.
- But there’s another option. Upon receiving a
notification, the subscriber can fetch any data
directly from the notification. In this case, the
publisher must pass itself via the update
method. The less flexible option is to link a
publisher to the subscriber permanently via the
constructor.
The client must create all necessary subscribers
and register them with proper publishers.
3.4. Use cases:
Whenever we’re interested in the state of an object
and want to get notified whenever there is any
change.
4. Strategy :
4.1. Intro :
This design pattern makes sure to adopt the
behavior and the algorithms of an object according to
the needs, without necessarily changing the
interactions of the object with the clients.
4.2. Structure :
4.3. Implementation :