FullStackCafe - Disgn Paterin

Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

FullStack.

Cafe - Kill Your Tech Interview

FullStack.Cafe - Kill Your Tech Interview

Q1: What is Design Patterns and why anyone should use them? ☆

Topics: Design Patterns

Answer:

Design patterns are a well-described solution to the most commonly encountered problems which occur during
software development.

Design pattern represents the best practices evolved over a period of time by experienced software developers.
They promote reusability which leads to a more robust and maintainable code.

Q2: What are the main categories of Design Patterns? ☆

Topics: Design Patterns

Answer:

The Design patterns can be classified into three main categories:

Creational Patterns
Behavioral Patterns
Functional Patterns

Q3: What is Singleton pattern? ☆

Topics: Design Patterns

Answer:

Singleton pattern comes under creational patterns category and introduces a single class which is responsible
to create an object while making sure that only single object gets created. This class provides a way to access its
only object which can be accessed directly without need to instantiate the object of the class.

Page 1 of 9
FullStack.Cafe - Kill Your Tech Interview

Q4: What is Dependency Injection? ☆☆

Topics: Design Patterns Dependency Injection

Answer:

Dependency injection makes it easy to create loosely coupled components, which typically means that
components consume functionality defined by interfaces without having any first-hand knowledge of which
implementation classes are being used.

Dependency injection makes it easier to change the behaviour of an application by changing the components
that implement the interfaces that define application features. It also results in components that are easier to
isolate for unit testing.

Q5: What is Inversion of Control? ☆☆

Topics: Design Patterns

Answer:

Inversion of control is a broad term but for a software developer it's most commonly described as a pattern used
for decoupling components and layers in the system.

For example, say your application has a text editor component and you want to provide spell checking. Your
standard code would look something like this:

public class TextEditor {

private SpellChecker checker;

public TextEditor() {
this.checker = new SpellChecker();
}
}

What we've done here creates a dependency between the TextEditor and the SpellChecker. In an IoC scenario we
would instead do something like this:

Page 2 of 9
FullStack.Cafe - Kill Your Tech Interview

public class TextEditor {

private IocSpellChecker checker;

public TextEditor(IocSpellChecker checker) {


this.checker = checker;
}
}

You have inverted control by handing the responsibility of instantiating the spell checker from the TextEditor class
to the caller.

SpellChecker sc = new SpellChecker; // dependency


TextEditor textEditor = new TextEditor(sc);

Q6: Can we create a clone of a singleton object? ☆☆

Topics: Design Patterns

Answer:

Yesl, we can but the purpose of Singleton Object creation is to have single instance serving all requests.

Q7: What is Factory pattern? ☆☆

Topics: Design Patterns

Answer:

Factory pattern is one of most used design pattern and comes under creational patterns category.

In Factory pattern, we create object without exposing the creation logic to the client and refer to newly created
object using a common interface.

Pro's:

Page 3 of 9
FullStack.Cafe - Kill Your Tech Interview

Allows you to hide implementation of an application seam (the core interfaces that make up your application)
Allows you to easily test the seam of an application (that is to mock/stub) certain parts of your application so
you can build and test the other parts
Allows you to change the design of your application more readily, this is known as loose coupling

Con's

Makes code more difficult to read as all of your code is behind an abstraction that may in turn hide
abstractions.
Can be classed as an anti-pattern when it is incorrectly used, for example some people use it to wire up a
whole application when using an IOC container, instead use Dependency Injection.

Q8: Name types of Design Patterns? ☆☆

Topics: Design Patterns

Answer:

Design patterns can be classified in three categories: Creational, Structural and Behavioral patterns.

Creational Patterns - These design patterns provide a way to create objects while hiding the creation logic,
rather than instantiating objects directly using new opreator. This gives program more flexibility in deciding
which objects need to be created for a given use case.

Structural Patterns - These design patterns concern class and object composition. Concept of inheritance is
used to compose interfaces and define ways to compose objects to obtain new functionalities.

Behavioral Patterns - These design patterns are specifically concerned with communication between objects.

Q9: What is Builder pattern? ☆☆

Topics: Design Patterns

Answer:

Builder pattern builds a complex object using simple objects and using a step by step approach. This builder is
independent of other objects.

Page 4 of 9
FullStack.Cafe - Kill Your Tech Interview

aClient

create aConcreteBuilder

create aDirector

Construct()

BuildPartA()

BuildPartB()

BuildPartC()

GetResult()

The Director class is optional and is used to make sure that the building steps are executed in the right order
with the right data by the right builder. It's about validation and delegation.

Builder/Director pattern's steps invocations could be semantically presented by method chaining or so called
Fluent Interface syntax.

Pizza pizza = new Pizza.Builder()


.cheese(true)
.pepperoni(true)
.bacon(true)
.build();

Q10: What is Filter pattern? ☆☆

Topics: Design Patterns

Answer:

Filter pattern or Criteria pattern is a design pattern that enables developers to filter a set of objects using
different criteria and chaining them in a decoupled way through logical operations. This type of design pattern
comes under structural pattern as this pattern combines multiple criteria to obtain single criteria.

Filter design pattern is useful where you want to add filters dynamically or you are implementing multiple
functionalities and most of them require different filter criteria to filter something. In that case instead of hard
coding the filters inside the functionalities, you can create filter criteria and re-use it wherever required.

List<Laptop> laptops = LaptopFactory.manufactureInBulk();


AndCriteria searchCriteria = new AndCriteria(
new HardDisk250GBFilter(),
new MacintoshFilter(),
new I5ProcessorFilter());
List<Laptop> filteredLaptops = searchCriteria.meets(laptops);

Page 5 of 9
FullStack.Cafe - Kill Your Tech Interview

Q11: What is Strategy pattern? ☆☆

Topics: Design Patterns

Answer:

In Strategy pattern, a class behavior or its algorithm can be changed at run time. This type of design pattern
comes under behavior pattern.

In Strategy pattern, we create objects which represent various strategies and a context object whose behavior
varies as per its strategy object. The strategy object changes the executing algorithm of the context object.

Q12: What is Template pattern? ☆☆

Topics: Design Patterns

Answer:

In Template pattern, an abstract class exposes defined way(s)/template(s) to execute its methods. Its
subclasses can override the method implementation as per need but the invocation is to be in the same way as
defined by an abstract class. This pattern comes under behavior pattern category.

Q13: What is Null Object pattern? ☆☆

Topics: Design Patterns

Answer:

Page 6 of 9
FullStack.Cafe - Kill Your Tech Interview

In Null Object pattern, a null object replaces check of NULL object instance. Instead of putting if check for a
null value, Null Object reflects a do nothing relationship. Such Null object can also be used to provide default
behaviour in case data is not available.

In Null Object pattern, we create an abstract class specifying various operations to be done, concrete classes
extending this class and a null object class providing do nothing implementation of this class and will be used
seamlessly where we need to check null value.

Q14: What is State pattern? ☆☆

Topics: Design Patterns

Answer:

In State pattern a class behavior changes based on its state. This type of design pattern comes under behavior
pattern. In State pattern, we create objects which represent various states and a context object whose behavior
varies as its state object changes.

Q15: What is Iterator pattern? ☆☆

Topics: Design Patterns

Answer:

Iterator pattern is very commonly used design pattern in Java and .Net programming environment. This
pattern is used to get a way to access the elements of a collection object in sequential manner without any need
to know its underlying representation. Iterator pattern falls under behavioral pattern category.

Page 7 of 9
FullStack.Cafe - Kill Your Tech Interview

Q16: What is Proxy pattern? ☆☆

Topics: Design Patterns

Answer:

In proxy pattern, a class represents functionality of another class. This type of design pattern comes under
structural pattern.

In proxy pattern, we create object having original object to interface its functionality to outer world.

Q17: What is IoC (DI) Container? ☆☆

Topics: .NET Core Dependency Injection

Answer:

A Dependency Injection container, sometimes, referred to as DI container or IoC container, is a framework


that helps with DI. It

creates and
injects

dependencies for us automatically.

Q18: What are some benefits of Repository Pattern? ☆☆

Page 8 of 9
FullStack.Cafe - Kill Your Tech Interview

Topics: Design Patterns

Answer:

A Repository Pattern allows all of your code to use objects without having to know how the objects are
persisted. All of the knowledge of persistence, including mapping from tables to objects, is safely contained in
the repository.

Under the covers:

for reading, it creates the query satisfying the supplied criteria and returns the result set
for writing, it issues the commands necessary to make the underlying persistence engine (e.g. an SQL
database) save the data

Very often, you will find SQL queries scattered in the codebase and when you come to add a column to a table
you have to search code files to try and find usages of a table. The impact of the change is far-reaching.

With the repository pattern, you would only need to change one object and one repository. The impact is very
small. There are other benefits too, for example, if you were using MySQL and wanted to switch to SQL Server.

Q19: Why would you want to use a Repository Pattern with an


ORM? ☆☆

Topics: Design Patterns

Answer:

The Repository abstract the access to all storage concerns. The Repository allows the rest of the
application to ignore persistence details. Repositories deal with Domain/Business objects.
The ORM abstract access to a specific RDBMS. An ORM handles db objects. The ORM is an implementation
detail of the Repository.

Page 9 of 9

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy