Introduction about design patterns to design an application.
Not all design patterns are presented here, just some of them.
This presentation has been done during our weekly lunch presentation.
3. Definition : Represent the best practices used by
experienced OO software developers.
Solutions to general problems that software developers
faced during software development.
2 main usages :
• Common platform for developers : provide a standard terminology and
are specific to particular scenario
• Best Practices : best solutions to certain problems faced during software
development
=> 23 different design patterns
7. Prototype pattern
• Specifying the kind of objects to create using a prototypical instance
• Creating new objects by copying this prototype
It is more convenient to copy an existing instance than to create a
new one.
• Avoid using “new” operator.
Ex : copy set of data from the DB or copy container of objects
8. Prototype pattern
public interface Prototype {
public abstract Object clone ( );
}
public class ConcretePrototype implements Prototype {
// Data set
public Object clone() {
return super.clone();
}
}
public class Client {
public static void main( String arg[] )
{
ConcretePrototype obj1= new ConcretePrototype ();
// fill obj1 with large amount of data / object or heavy tasks
ConcretePrototype obj2 = ConcretePrototype)obj1.clone();
}
}
10. Bridge Patterns
The implementation of an abstraction can be
configured and even switched at run-time.
Abstraction and Implementor hierarchies can be
extended independently
meworks use the bridge pattern to separate abstractions from platform specific implementation (for example on
Decouple abstraction from implementation so
that the two can vary independently.
13. Flyweight Patterns
Minimise memory use by sharing as much
data as possible with similar objects.
Exemple : ressources (in video games)
saves memory, depends on the number of flyweight categories saved
public class ShapeFactory {
private static final HashMap<String, Shape> circleMap = new HashMap();
public static Shape getCircle(String color) {
Circle circle = (Circle)circleMap.get(color);
if(circle == null) {
circle = new Circle(color);
circleMap.put(color, circle);
System.out.println("Creating circle of color : " + color);
}
return circle;
}
}
15. Command Patterns Encapsulate a request as an object, in a
queue. Can be parameterise
- Another objects can manipulate the request even
without knowing any information about it.
- The command is just a link between the receiver and
the actions that carry out the request.
- The command implements everything itself, without
sending anything to the receiver.
16. Mediator Patterns
Intermediary / play the role of a controller between objects
Design reusable components
Loose coupling between objects
17. Observer Patterns
The "View" part of Model-View-Controller.
Defines a one-to-many relationship : one object
changes state, the others are notified and updated
automatically.
Example : subscription NL, auction