Design Patterns Flashcards
What are Design Patterns?
A design pattern is a general reusable solution to a commonly occurring problem within a given context in software design. A design pattern is not a finished design that can be transformed directly into source or machine code. It is a description or template for how to solve a problem that can be used in many different situations. Patterns are formalized best practices that the programmer can use to solve common problems when designing an application or system
What all are the advantages of Design Patterns?
Patterns solve software structural and non functional problems.
Structural problems like:
Abstraction Encapsulation Data Hiding Separation of Concerns Separation of Interface and Implementation Single point of reference Coupling and Cohesion etc.. Non Functional problems like:
Efficiency Reliability Interoperability Testability Reusability etc..
What all are the types of Design Patterns?
There are 3 types of Design Pattern.
Creational Patterns
This type of pattern address problems of creating an object and separating it from operations
Structural Patterns
This type of pattern address problems of using object oriented constructs to organize classes and objects
Behavioral Patterns
This type of pattern address problems of assigning responsibilities to classes
What is Structural Design Pattern?
Structural patterns are concerned with how classes and objects are composed to form larger structures; the class form of the Adapterdesign pattern is an example.
Structural class patterns use inheritance to compose interface or implementations.
Structural Design Patterns are Design Patterns that ease the design by identifying a simple way to realize relationships between entities.
In C#, We have 7 types of design patterns in Structural Catagory.
Adapter Bridge Composite Decorator Facade Flyweight Proxy
What is Singleton Design Pattern?
Singleton ensures a class only has one instance. Singleton Provides a global point of access to it.
What is Factory Design Pattern?
Factory Design patterns:
Define an Interface for creating an object but let subclasses decide which class to instantiate Lets a class defer instantiation to subclasses
What is Abstract Factory Design Pattern?
Provides an interface for creating families of related or dependent objects without specifying their concrete classes.
Abstract Factory patterns acts a super-factory which creates other factories. This pattern is also called as Factory of factories
What is Prototype Design Pattern?
Prototype pattern specifies the kind of objects to create using a prototypical instance, and create new objects by copying this prototype.
It is used to create a duplicate object or clone of the current object to enhance performance.
What is Builder Design Pattern?
Separate the construction of a complex object from its representation so that the same construction process can create different representations.
In other words,you will have to design the system in such a way that the client application will simply specify the parameters that should be used to create the complex object and the builder will take care of building the complex object.
What is Adapter Design Pattern?
The adapter pattern is adapting between classes and objects This pattern involves a single class called adapter which is responsible for communication between two independent or incompatible interfaces This works like a bridge between two incompatible interfaces
What is Bridge Design Pattern?
Bridge Pattern separates abstraction from its implementation, so that both can be modified Independently Bridge Pattern behaves like a bridge between abstraction class and Implementer class.
What is Composite Design Pattern?
Composite pattern composes objects in term of a tree structure to represent part as well as whole hierarchies. Composite pattern creates a class contains group of its own objects. This class provides ways to modify its group of same objects. Composite pattern is used when we need to treat a group of objects and a single object in the same way
What is Decorator Design Pattern?
Decorator pattern is used to add new functionality to an existing object without changing its structure. Decorators provide a flexible alternative to subclass for extending functionality. This pattern creates a decorator class which wraps the original class and add new behaviors/operations to an object at run-time.
What is Facade Design Pattern?
Facade Design Pattern makes a software library easier to use, understand and test
Facade Design Pattern make the library more readable
Facade Design Pattern reduce dependencies of outside code on the inner workings of a library
Facade Design Pattern wrap a poorly designed collection of APIs with a single well-designed API.
What is Flyweight Design Pattern?
Flyweight design pattern is an object that minimizes memory use by sharing as much data as possible with other similar objects
Flyweight pattern is used to reduce the number of objects created, to decrease memory and resource usage. As a result it increase performance
Flyweight design pattern provides a way to use objects in large numbers when a simple repeated representation would use an unacceptable amount of memory.
The flyweight pattern uses the concepts of intrinsic and extrinsic data.Intrinsic datais held in the properties of the shared flyweight objects. This information is stateless and generally remains unchanged, if any change occurs it would be reflected among all of the objects that reference the flyweight.Extrinsic data is computed on the fly means at runtime and it is held outside of a flyweight object. Hence it can be stateful.