Design Patterns Flashcards
What is Design Patterns ?
Design patterns are solutions for problems faced during software development , they are best practices used by developers.
What is GOF (Gang Of Four) ?
GOF are 4 authors Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides published a book titled Design Patters - Elements of Reusable Object-Oriented Software which initiated concept of Design Patterns in software development.
What are design patterns based on?
*Program to an interface not implementation
*Favor object composition over inheritance
What is usage of design patterns ?
*Common platform for developers: Standard terminology and are specific to a particular scenario.
*Best practices
How many Design Patterns we have ?
23
Types of Design Patterns
*Creational Patterns
*Structural Patterns
*Behavioral Patterns
*J2EE Patterns
What are Creational Patterns ?
Creational Patterns provides a way to create object while hiding creation logic rather than using instantiation with new operator.
=>Benefits: Increase flexibility + reusable code
What are Structural Patterns ?
Structural Patterns consist on assembling objects and classes to larger structures , while keeping these structures flexible and efficient
What are Behavioral Patterns ?
Behavioral patterns are concerned with communication between objects.
What are J2EE Patterns ?
J2EE Patterns are concerned with the presentation tier
What is Factory Pattern ?
Factory is a creational pattern that provides an interface for creating objects in a super class, but allows subclasses to alter the type of objects that will be created.
Extends Abstract Factory class (not yet a certain factory , its true nature not revealed yet )
_________________________________________________
Examples:
*We have a Shape Factory we created Circle , customer want a Rectangle that’s where Factory pattern come , it creates the alter the shape independently of the other using Shape interface.
_________________________________________________
IS this correct ??? :
*We have a burger without knowing it’s ingredients
_________________________________________________
What is Abstract Factory Pattern ?
is a creational pattern for producing families of related objects without specifying their concrete classes.
it’s working around a super factory which creates other factories.
________________________________________
Example:
Creating an AbstractFactory containing RoundedShape and SimpleShape Factories , RoundedShape Factory to create
products with rounded shape ,same for SimpleShape Factory, which construct shape (interface) that contains all shapes.
What is Builder Pattern ?
Builder is a creactional pattern, for creating complex objects step by step. To produce different types and representations of an object with the same construction code.
*We have control over ingredients used to construct our burger
What is Singleton Pattern ?
Singleton is a creational pattern, that let you ensure that a class has only one instance while providing global access to this instance (Single Responsibility Principle), and provide a way to access an object without the need to instantiate it.
=>instantiate one time the only object inside class , if it change all components that use it change there object value
What is Observer Pattern ?
Observer is a behavioral pattern,
*Come to picture when singleton updates all its components in real time
*PubSub : when a user publish a video on youtube , youtube notify all subscribers