18
How to design an application correctly? Touch Surgery Lunch Presentation 03/02/2014

How to design an application correctly ?

Embed Size (px)

Citation preview

Page 1: How to design an application correctly ?

How to design an application correctly?

Touch Surgery Lunch Presentation 03/02/2014

Page 2: How to design an application correctly ?

What is a design pattern?

Page 3: How to design an application correctly ?

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

Page 4: How to design an application correctly ?

• Creational Patterns

• Structural Patterns

• Behavioral Patterns

Type of design patterns

Page 5: How to design an application correctly ?

Creational Patterns

Creation object

flexibility

Page 6: How to design an application correctly ?

Builder & Factory pattern

Page 7: How to design an application correctly ?

Prototype pattern

• Specifying the kind of objects to create using a prototypical instance

• Creating new objects by copying this prototypeIt 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

Page 8: How to design an application correctly ?

Prototype patternpublic interface Prototype {

public abstract Object clone ( );}

public class ConcretePrototype implements Prototype {

// Data setpublic 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();

}

}

Page 9: How to design an application correctly ?

Structural Patterns

Concept of inheritance

Compose objects to obtain new functionalities.

Page 10: How to design an application correctly ?

Bridge Patterns

The implementation of an abstraction can be configured and even switched at run-time.Abstraction and Implementor hierarchies can be extended independently

Example : GUI Frameworks use the bridge pattern to separate abstractions from platform specific implementation (for example on Windows or linux).

Decouple abstraction from implementation so that the two can vary independently.

Page 11: How to design an application correctly ?

Bridge Patterns

Page 12: How to design an application correctly ?

Decorator Patterns

Add/remove additional responsibilities dynamically to an

objectExample : Extending capabilities of a

Graphical Window at runtime

Page 13: How to design an application correctly ?

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; }}

Page 14: How to design an application correctly ?

Behavioral Patterns

Communication between objects

Page 15: How to design an application correctly ?

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.

Page 16: How to design an application correctly ?

Mediator Patterns

Intermediary / play the role of a controller between objects

Design reusable componentsLoose coupling between objects

Page 17: How to design an application correctly ?

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

Page 18: How to design an application correctly ?