Final Flashcards
used when we need to decouple an abstraction from its implementation so that the two can vary independently. This type of design pattern comes under structural pattern as this pattern decouples implementation class and abstract class by providing a bridge structure between them.
Bridge
This pattern involves an interface which acts as a connection which makes the functionality of concrete classes independent from interface implementer classes. Both types of classes can be altered structurally without affecting each other.
Bridge
behavioral software design pattern that implements a machine in an object -oriented way . is implemented by implementing each individual as a derived class of the interface , and implementing transitions by invoking methods defined by the pattern’s superclass
State design pattern
can be interpreted as a strategy pattern which is able to switch the current strategy through invocations of methods defined in the pattern’s interface.
state pattern
This pattern is used in computer programming to encapsulate varying behavior for the same object based on its internal state. This can be a cleaner way for an object to change its behavior at runtime without resorting to large monolithic conditional statements and thus improve maintainability
State design pattern
is the degree of interdependence between software modules; a measure of how closely connected two routines or modules are; the strength of the relationships between modules.
coupling
refers to the degree to which the elements of a module belong together. measures the strength of relationship between pieces of functionality within a given module.
Cohesion
All good software design will go for HIGH __________ and LOW _________
cohesion
coupling
We must have:
We want good:
Coupling
Coupling
is used to describe just how much an outside class can get into another class’s members:
is used to describe just how much access an outside class has to another class with a well designed API:
Tight Coupling
Loose coupling
is a principle of software development, aimed at reducing repetition of information of all kinds, especially useful in multi-tier architectures.
DRY
Principles of object oriented design: SOLID
(SRP) Single responsibility principle
(OCP) Open Close Principle
(LSP) Liskov substitution principle
(ISP) Interface Segregation principle
(DIP) Dependency Inversion principle
says “Every software module should have only one reason to change” Software Module Class, Function etc. Reason to change Responsibility
Single responsibility principle SRP
says, “Software modules should be closed for modifications but open for extensions.”
Open close principle OCP
says, “Subclasses should be substitutable for base classes.”
Liskov substitution principle LSP
states that if a program module is using a Base class, then the reference to the Base class can be replaced with a Derived class without affecting the functionality of the program module .
Likov’s Substitution Principle
states that a client should never be forced to implement an interface that it doesn’t use or clients shouldn’t be forced to depend on methods they do not use.
Interface segregation principle ISP
says, “High level modules should not depend upon low level modules . Rather , both should depend upon abstractions .”
Dependency inversion principle DIP
Entities must depend on abstractions not on concretions. It states that the high level module must not depend on the low level module, but they should depend on abstractions.
Dependency inversion principle DIP
Who are the Gang of Four (GOF)
Erich Gamma
Richard Helm
Ralph Johnson
John Vlissides
Elements of Reusable Object -Oriented
Design Patterns
Software Defined original how many design patterns
23
Creates an instance of several families of classes:
Separates object construction from its representation:
Creates an instance of several derived classes:
Avoid expensive acquisition and release of resources by recycling objects that are no longer in use:
A fully instance to be copied or cloned:
A class of which only a single instance can exist:
Abstract Factory
Builder
Factory method
Object Pool (Non GOF)
Prototype
Singleton
Design patterns are about class instantiating:
Abstract factory
Builder
Factory method
Object pool
Prototype
Singleton
Match interfaces of different classes:
Separates an object’s interface from its implementation:
A tree structure of simple and composite objects:
Add responsibilities to objects dynamically:
A single class that represents an entire subsystem:
A fine-grained instance used for efficient sharing:
Restricts accessor /mutator access:
An object representing another object:
Adapter
Bridge
Composite
Decorator
Facade
Flyweight
Private Class Data (Non -GOF )
Proxy
Design pattern are all about class and object composition:
Adapter
Bridge
Composite
Decorator
Facade
Flyweight
Private Class Data (Non -GOF )
Proxy
A way of passing a request between a chain of objects:
Encapsulate a command request as an object:
A way to include language elements in a program:
Sequentially access the elements of a collection:
Defines simplified communication between classes:
Capture and restore an object’s internal state:
Designed to act as a défault value of an object:
A way of notifying change to a number of classes:
Alter an object’s behavior when its state changes:
Encapsulates an algorithm inside a class:
Defer the exact steps of an algorithm to a subclass:
Defines a new operation to a class without change:
Chain of responsibility
Command
Interpreter
Iterator
Mediator
Memento
Null Object (Non-GOF )
Observer
State
Strategy
Template method
Visitor
Design pattern are all about a class’s objects communication:
Chain of responsibility
Command
Interpreter
Iterator
Mediator
Memento
Null Object (Non-GOF )
Observer
State
Strategy
Template method
Visitor
abstract the instantiation process. They help make a system independent of how its objects are created, composed, and represented. uses inheritance to vary the class that’s instantiated, whereas an object pattern will delegate instantiation to another object.
Creational design patterns
Provide an interface for creating families of related or dependent objects without specifying their concrete classes.
Abstract Factory
Separate the construction of a complex object from its representation so that the same construction process can create different representations.
Builder
Define an interface for creating an object, but let subclasses decide which class to instantiate. lets a class defer instantiation to subclasses
Factory method
Specify the kinds of objects to create using a prototypical instance , and create new objects by copying .
Prototype
Ensure a class only has one instance, and provide a global point of access to it.
Singleton
are concerned with how classes and objects are composed to form larger structures. use inheritance to compose interfaces or implementations . As a simple example, consider how multiple inheritance mixes two or more classes into one. The result is a class that combines the properties of its parent classes. This pattern is particularly useful for making independently developed class libraries work together.
Structural design patterns
lets classes work together that couldn’t otherwise because of incompatible interfaces .
Adapter
Decouple an abstraction from its implementation so that the two can vary independently
Bridge
Compose objects into tree structures to represent part- whole hierarchies. lets clients treat individual objects and of objects uniformly
Composite
Attach additional responsibilities to an object dynamically. provide a flexible alternative to subclassing for extending functionality.
Decorator
Provide a unified interface to a set of interfaces in a subsystem . defines a higher-level interface that makes the subsystem easier to use.
Facade
Use sharing to support large numbers of fine-grained objects efficiently
Flyweight
Provide a surrogate or placeholder for another object to control access to it.
Proxy
are concerned with algorithms and the assignment of responsibilities between objects. describe not just patterns of objects or classes but also the patterns of communication between them. These patterns characterize complex control flow that’s difficult to follow at run-time. They shift your focus away from flow of control to let you concentrate just on the way objects are interconnected.
Behavioral design patterns
Avoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request. Chain the receiving objects and pass the request along the chain until an object handles it.
Chain of responsibility
Encapsulate a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations.
Command
Given a language, define a representation for its grammar along that uses the representation to interpret sentences in the language
interpreter
Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation.
Iterator
Define an object that encapsulates how a set of objects interact . promotes loose coupling by keeping objects from referring to each other explicitly, and it lets you vary their interaction independently
Mediator
Without violating encapsulation, capture and externalize an object’s internal state so that the object can be restored to this state later.
Memento
Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.
Observer
Allow an object to alter its behavior when it’s internal state changes. The object will appear to change its class.
State
Define a family of algorithms, encapsulate each one, and make them interchangeable. lets the algorithm vary independently from clients that use it.
Strategy
Define the skeleton of an algorithm in an operation, deferring some steps to subclasses. lets subclasses redefine certain steps of an algorithm without changing the algorithm’s structure.
Template Method
Represent an operation to be performed on the elements of an object structure. lets you define a new operation without changing the classes of the elements on which it operates.
Visitor