Presentation on theme: "Welcome to. Who am I? A better way to code Design Patterns ??? What are design patterns? How many are there? How do I use them? When do I use."— Presentation transcript:
Who am I?
A better way to code
Design Patterns ??? What are design patterns? How many are there? How do I use them? When do I use them?
What are design patterns?
“Design patterns are recurring solutions to software design problems you find again and again in real-world application development” – dofactory.com
What are design patterns? Design Patterns not only allow you to reuse a code solution, but help provide extensibility, maintainability, and a way for fellow programmers to understand the solution.
How many patterns are there? 23 + Creational Patterns Abstract Factory :- Creates an instance of several families of classes Builder : - Separates object construction from its representation Factory Method :- Creates an instance of several derived classes Prototype :- A fully initialized instance to be copied or cloned Singleton :- A class in which only a single instance can exist
How many patterns are there? Structural Patterns Adapter :- Match interfaces of different classes. Bridge :- Separates an object's abstraction from its implementation. Composite :- A tree structure of simple and composite objects. Decorator :- Add responsibilities to objects dynamically. Façade :- A single class that represents an entire subsystem. Flyweigh t:- A fine-grained instance used for efficient sharing. Proxy :- An object representing another object.
How many patterns are there? Behavioral Patterns Mediator :- Defines simplified communication between classes. Memento :- Capture and restore an object's internal state. Interpreter :- A way to include language elements in a program. Iterator :- Sequentially access the elements of a collection. Chain of Resp : - A way of passing a request between a chain of objects. Command :- Encapsulate a command request as an object. State :- Alter an object's behavior when its state changes. Strategy :- Encapsulates an algorithm inside a class. Observer : - A way of notifying change to a number of classes. Template Method :- Defer the exact steps of an algorithm to a subclass. Visitor :- Defines a new operation to a class without change.
Are design patterns new? Nope! In fact they have been around a long time! “ Design patterns have their roots in the work of Christopher Alexander, a civil engineer who wrote about his experience in solving design issues as they related to buildings and towns. It occurred to Alexander that certain design constructs, when used time and time again, lead to the desired effect.” --developer.com/article.php/
How do I use a design pattern? First is being exposed to what’s there. With 23 common patterns plus the custom ones, there’s plenty to pick from. Second, getting resources to explain them in enough detail you’ll easily understand them and how they’ll fit your needs.
Resources… Highly recommend for beginners to design patterns. Breaks things down to make very easy to understand.
Resources… A definitive text on all the design patterns. GoF Very deep coverage
Resources… Another definitive book Very deep coverage
When do I use a design pattern? When you see if-else or switch statements – that may need a pattern When there is a lot of complexity in method(s) reusing the same logic – that may need a pattern When it is hard to test methods and/or logic – that may need a pattern
When do I use a design pattern? Design patterns should be applied when the problem being solved can be solved using a documented design pattern. The problem should always come first. Only then should pattern knowledge be applied when coming up with a solution. Patterns are not solutions looking for a place to use them. Will the pattern add value and simplify the solution?
Encapsulates an algorithm inside a class
Strategy Design Pattern -UML Allows one of a family of algorithms to be selected on-the-fly at runtime.
Strategy Design Pattern Allows us to divide up the behaviors Used to provide a model for quickly updating and changing behaviors as needed Allows for a wide variety of behaviors without having to maintain a bajillion classes