Design Patterns and Principles Chapter 2 Flashcards
____ _____ ____ in python focus on HOW objects are created and managed, ensuring flexibility, efficiency, and maintainability in your code.
They provide a structured approach to object instantiation, making it easier to control the creation process and decouple the creation logic from the rest of you application.
Creational Design Pattern
Creational Design Pattern(s) (SFABP)
Singleton
Factory Method
Abstract Factory
Builder
Prototype
One of the simplest design patterns: it involves only ONE CLASS which is responsible to MAKE SURE THERE IS NO MORE THAN ONE INSTANCE; it does it by instantiating itself and in the same time it provides a GLOBAL POINT OF ACCESS to that instance.
Singleton
Ensure that only one instance of a class is created and provide access point to the object
Singleton
The most used design pattern in modern programming languages like Java and C#. It comes in different variants and implementation
Factory Method
Defines an interface for creating objects, but let subclasses to decide which class to instantiate and Refers to the newly created object through a common interface.
Creates OBJ w/o exposing INST Logic to client
Ref to newly created OBJ thru COMMON INTERFACE
FACTORY MODE
A pattern that provides an interface for creating families of related or dependent object without specifying their concrete classes.
Abstract factory
To avoid adding code to existing classes and to support encapsulation, with this pattern a framework is defined, which produces objects that follow a general pattern and at runtime this facotry is paired with any concrete factory to produce objects that follow the pattern of a certain country
A super-factory which creates other factories(Factory of factories)
Abstract FACTORY
Defines an instance of creating an object but letting subclasses decide which class to instantiate and allows a finer control over the construction process.
Defines an instance for creating an object but letting subclasses decide which class to instantiate
Refers to the newly created object through a common interface
Builder
allows an object to create customized objects without knowing their class or any details of how to create them.
Prototype
Specify the kinds of objects to create using a prototypical instance, and create new objects by copying this prototype
Lets you copy existing objects without making your code dependent on their classes
Useful when object creation is constly
Prototype
are a subset of design pattern in software development that focus on the composition of classes or objects to form a larger, more complex structures
Structural Design Pattern
Structural Design Patter(s)(ABCDFPF)
Adapter
Bridge
Composite
Decorator
Flyweight
Proxy
Facade
A structural design pattern, it allows you to make TWO INCOMPATIBLE interfaces WORK TOGETHER by creating a bridge between them
Use when you need to make incompatible interface work
Adapter
The intent of this pattern is to DECOUPLE ABSTRACTION from implementation so that the two can vary INDEPENDENTLY.
Use when you want to separate an abstraction from its implementation
Bridge
The intent of this pattern is to COMPOSE objects into TREE STURCTURES to represent part-whole hierarchies.
Composite
Lets client treat individual objects and composition of objects uniformly.
Useful when you need to treat individual objects and composition uniformly
Composite
Extending an object’s functionality can be done ______
(at compile time) by using inheritance
statically
However, it might be necessary to extend an object’s
functionality _______(at runtime) as an object is
used.
dynamically
Allows to add behavior to individual objects, either statically or dynamically, without affecting the behavior of other objects from the same class.
useful when you need to add responsibilities to objects dynamically
Decorator
A structural design pattern that allwos program to efficiently share many objects by minimizing memory usage
Flyweight
Provide to create a substitue for an object, which can act as an intermediary or control access to the real object.
The intent of this pattern is to provide a placeholder for an object to control references to it
Useful wehn you need to control access to an object, or defer its full cost
Proxy
Provides a simple interface to a complex subsystem which contains lots of moving parts. Its handy when you need to integrate your app with a sophisticated library that has dozen of features, but you just need a tiny bit of its functionality.
FACADE