Creational Design Pattern Design Patterns and Principles Chapter 2 Part 1 Flashcards

1
Q
  • 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 your application
A

Creational design patterns

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
  • are used for centralized management of internal or external resources and they provide a global point of access to themselves
  • is 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
  • Ensure that only one instance of a class is created and Provide a global access point to the object.
A

SINGLETON

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

When to use SINGLETON

A

○ Singleton pattern should be used when we must ensure that only one instance of a class is created and when the instance must be available through all the code.
○ A special care should be taken in multi-threading environments when multiple threads must access the same resources through the same singleton object.

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

SINGLETON
Common Uses

A


Logger Classes

Configuration Classes

Accessing resources in shared mode

Database connections

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
  • is probably the most used design pattern in modern programming languages like Java and C#. It comes in different variants and implementations.
  • 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.
A

FACTORY METHOD

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

FACTORY METHOD
When to use

A


A framework delegate the creation of objects derived from a common superclass to the factory

the base factory class does not know what concrete classes will be required to create -delegates to its subclasses the creation of concrete objects

factory subclasses subclassesare aware of the concrete classes that must be instantiated

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

FACTORY METHOD
Common Uses

A

○ Along with singleton pattern, the factory method is the most used pattern.
○ Almost any application has some factories. Here are a some examples:
○ factories providing an xml:
■ parser:javax.xml.parsers.DocumentBuilderFactory

javax.xml.parsers.SAXParserFactory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
  • is used. Using this pattern a framework is defined, which produces objects that follow a general pattern and at runtime this factory is paired with any concrete factory to produce objects that follow the pattern of a certain country.
    -is a super-factory which creates other factories (Factory of factories).
  • A pattern that provides an interface for creating families of related or dependent objects without specifying their concrete classes..
A

ABSTRACT FACTORY

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

ABSTRACT FACTORY
When to use

A


A system should be configured with one of multiple families of products

A system should be independent of how its products are created, composed and represented

Products from the same family should be used all together, products from different families should not be used together and this constraint must be ensured.

Only the product interfaces are revealed, the implementations remains hidden to the clients.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
  • are made of parts produced by other objects that need special care when being built
  • Defines an instance for creating an object but letting subclasses decide which class to instantiate and Allows a finer control over the construction process.
A

BUILDER

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

BUILDER when to use

A


Useful when an object needs to be created with many possible configurations

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q
  • allows an object to create customized objects without knowing their class or any details of how to create them.
A

PROTOTYPE

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

PROTOTYPE when to use

A


Useful when object creation is costly

Cloning documents with different content but similar structure

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