How to

#design patterns #software development #Interview Questions

Design Patterns

What is a “design pattern”?

A design pattern is a proven and ready-to-use solution. It is not a class or a library that can be plugged into a project; it’s something more than that – it is language-independent, not a finished example that can be directly converted into code, and it can be implemented in different ways across various programming languages.

Advantages of Using Patterns:

Disadvantages:

Back to Table of Contents

Name the main characteristics of design patterns.

Back to Table of Contents

Types of Design Patterns.

Back to Table of Contents

Provide examples of main design patterns.

Back to Table of Contents

Provide examples of creational design patterns.

Back to Table of Contents

Provide examples of structural design patterns.

Back to Table of Contents

Provide examples of behavioral design patterns.

Back to Table of Contents

What is an “anti-pattern”? What anti-patterns do you know?

An anti-pattern is a common approach to solving a class of frequently encountered problems that is ineffective, risky, or unproductive.

Poltergeists - Classes with limited responsibility and role in the system, whose sole purpose is to pass information to other classes. Their effective lifecycle is short. Poltergeists disrupt the cohesion of software architecture by creating redundant abstractions; they are overly complex, difficult to understand, and hard to maintain. Such classes are often designed as controller classes that exist solely to invoke methods on other classes, frequently in a predefined sequence.

Signs of Appearance and Consequences of the Anti-Pattern:

Typical Causes:

Introduced Complexity: Optional design complexity. Instead of having a single simple class, an entire hierarchy of interfaces and classes is created. A typical example is “Interface - Abstract Class - Only Class Implementing Interface based on Abstract”.

Abstraction Inversion: Hiding part of the functionality from external use, hoping that no one will use it.

Ambiguous Viewpoint: Presenting a model without specifying its viewpoint.

Big Ball of Mud: A system with unrecognizable structure.

God Object: Concentration of too many functions in one part of the system (class).

Input Kludge: Forgetfulness in specifying and performing support for potential incorrect input.

Interface Bloat: Development of an interface that is too powerful and very complex to implement.

Magic Pushbutton: Performing user action results through an unsuitable (not abstract enough) interface. For example, writing application logic in button click handlers.

Re-Coupling: The process of introducing unnecessary dependencies.

Stovepipe System: A rarely maintained assembly of poorly connected components.

Race Hazard: The unforeseen possibility of events occurring in a different order than expected.

Mutilation: Excessive “sharpening” of an object for a very narrow task, rendering it incapable of working with any other tasks, even very similar ones.

Save or Die: Saving changes only upon application exit.

Back to Table of Contents

What is Dependency Injection?

Dependency Injection is a set of patterns and principles in software development that allow you to write loosely coupled code. In full accordance with the single responsibility principle, an object delegates the responsibility for constructing the required dependencies to an external mechanism specifically designed for this purpose.

Back to Table of Contents

Sources

Interview Questions