Design Patterns Flashcards

1
Q

What is Design Patterns ?

A

Design patterns are solutions for problems faced during software development , they are best practices used by developers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is GOF (Gang Of Four) ?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are design patterns based on?

A

*Program to an interface not implementation
*Favor object composition over inheritance

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is usage of design patterns ?

A

*Common platform for developers: Standard terminology and are specific to a particular scenario.
*Best practices

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How many Design Patterns we have ?

A

23

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Types of Design Patterns

A

*Creational Patterns
*Structural Patterns
*Behavioral Patterns
*J2EE Patterns

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are Creational Patterns ?

A

Creational Patterns provides a way to create object while hiding creation logic rather than using instantiation with new operator.
=>Benefits: Increase flexibility + reusable code

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are Structural Patterns ?

A

Structural Patterns consist on assembling objects and classes to larger structures , while keeping these structures flexible and efficient

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are Behavioral Patterns ?

A

Behavioral patterns are concerned with communication between objects.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are J2EE Patterns ?

A

J2EE Patterns are concerned with the presentation tier

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is Factory Pattern ?

A

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
_________________________________________________

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is Abstract Factory Pattern ?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is Builder Pattern ?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is Singleton Pattern ?

A

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), without the need to instantiate it from outside.
=>instantiate one time the only object inside class , if it change all components that use it change there object value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is Observer Pattern ?

A

Observer is a behavioral pattern, that let’s you define a subscription mechanism to notify multiple objects about any events that happen to the object they’re observing ( when publisher make updates).
=> one to many relationship between publisher and subscribers.
=> Comes to picture when Singleton updates all its components in real time
*PubSub : when a user publish a video on youtube , youtube notify all subscribers
__________________________________________
Observer uses three main actors : Publisher(Subject) , Subcriber/Observer(Interface/abstract class), Concrete subscribers (clients).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is Iterator Pattern ?

A

Iterator is a behavioral pattern that lets you traverse elements of a collection in a sequential manner without exposing its underlying representation (list,stack,tree…)
Iterator has two main actors : Iterator and Container

17
Q

What is Strategy Pattern ?

A

Strategy is a behavioral pattern,that let’s you define a family of algorithms , put each one of them in a separate class , and make their objects interchangeable.
=>Strategy pattern has three main actors : Context ( use a strategy ) , Strategy (an interface to group all concrete strategies ), concrete strategies.
*OCP (open closed principle ):open to extensibility , closed to modification

18
Q

What is Adapter Pattern ?

A

Adapter is a structural pattern,that allows objects with incompatibles interfaces to collaborate(works as a bridge between two incompatible interfaces).
This pattern involves a single class which is responsible to join functionnalities of independant of incompatible interfaces
_________________________________________
Examples:
*When we have an XML data and we need to analyze it using a library that accept only json data , an adapter can convert XML to JSON ( and can do it also on inverse sense).
*When a Usb port can t enter a computer we use an adapter so it is convenient for Usb port

19
Q

What is Facade Pattern ?

A

Facade is a structural pattern, that provides an interface to the client to access a system , in order to hide complexities of the system.
*conceal unpleasant / credible reality (complex process) with outward appearance (simplified and easy use and command).
_____________________________________________
Examples:
*A client need a shop , he contact an agent in the shop (Facade class) who manage shopping operations(Interface provided) like packing , delivry , payment process,taxes…