Object Oriented Design Flashcards

1
Q

What are design patterns?

A

In software engineering, a design pattern is a general repeatable solution to a commonly occurring problem in software design.

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

What types of design patterns exist?

A

Creational, Structural, Behavioural

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

Factory Pattern (Creational)

A

Many design patterns are similar from a code point of view. What really changes is their intention which is depicted by the name of the pattern. The factory pattern allows to create a new object at runtime based on some input which can be a configuration file, some data introduced by a user, etc. In order to keep our code highly cohesive and loosely coupled, we can put the branches leading to the creation of different objects in a director class. These objects will contain, if it’s needed, some predefined values that will passed to our final objects’ constructors.

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

Builder Pattern (Creational)

A

It’s used to provide specifications in order to create a new object and avoid using telescoping constructors. One of the ways to do this is using for example using a static method named builder which returns an instance of a static inner which using the concept of fluid setters allows us to build a new object.

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

Facade (Structural)

A

A facade is an object that serves as a front-facing interface masking more complex underlying or structural code. A facade can.

  • improve the readability and usability of a software library by masking interaction with more complex components behind a single (and often simplified) API
  • provide a context-specific interface to more generic functionality (complete with context-specific input validation)
  • serve as a launching point for a broader refactor of monolithic or tightly-coupled systems in favor of more loosely-coupled code
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Proxy (Structural)

A

A proxy is a wrapper or agent object that is being called by the client to access the real serving object behind the scenes. Use of the proxy can simply be forwarding to the real object, or can provide additional logic.

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

Strategy (Behavioral)

A

Many design patterns are similar from a code point of view. What really changes is their intention which is depicted by the name of the pattern.

The strategy pattern allows to select an algorithm at runtime.

Instead of implementing a single algorithm directly, code receives run-time instructions as to which in a family of algorithms to use

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

Iterator (Behavioral)

A

The iterator pattern is a design pattern in which an iterator is used to traverse a container and access the container’s elements.

Iterator interface has the following methods:

  • hasNext()
  • next()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly