Top Software Architecture Interview Questions

1) Explain SOLID principles ?
-> Single Responsibility Principle
A module should be responsible to one, and only one, actor.
-> Open/Closed Principle
->A software artifact should be open for extension but closed for modification.
-> Liskov Substitution Principle
         -> It should be possible to substitute the derived class with base class.
-> Interface Segregation Principle
-> Many client specific interfaces are better than one-general purpose interface.
-> Dependency Inversion Principle
-> Depend upon Abstractions but not on concretions. This means that each module should be separated from other using an abstract layer which binds them together.

2) What is a Monolith application ?
-> A monolith application built as a single unit.
-> Enterprise applications are often built in three main parts. A client-side user interface (consisting of HTML pages and JavaScript  running in browser on the user’s machine), a database (consisting of many tables inserted into a common and usually a relational DBMS) and a server-side application. The server side application will handle HTTP requests, execute domain logic, retrieve and update data from the database and select and populate HTML views to be sent to the server.
-> This server side application is a monolith – a single logical executable. Any changes to the system involving building and deploying a new version of the server-side application.
-> You can horizontally scale the monolith by running many instances behind a load-balancer.

3) What are Microservices ?
-> Microservices are a style of software architecture that involves delivering systems as a set of very small, granular, independent collaborating services.
-> The services are easy to replace, Services can be implemented using different programming languages, databases, hardware and software environment depending on what fits best.

4) What are Design Patterns ?
-> Design patterns are optimized reusable solutions to the programming problems that we encounter every day.
-> Generic solutions to the common problems which are encountered in object oriented design.

5) What are Creational Design Patterns ?
-> Creational design patterns provide instantiation mechanisms, making it easier to create objects in a way that suits the situation.
1) Singleton
2) Factory
3) Abstract Factory
4) Builder
5) Prototype

6) What are Structural Design Patterns ?
-> Structural design patterns generally deal with relationships between entities, making it easier for these entities to work together.
1) Adaptor
2) Facade
3) Proxy
4) Bridge
5) Composite
6) Decorator
7) Flyweight

7) What are Behavioral Design Patterns ?
-> Behavioral design patterns are used in communications between entities and make it easier and more flexible for these entities to communicate.
1) Observer
2) Command
3) Chain of Responsibility

8) What is Singleton Design Pattern ?
-> Singleton Design Pattern is a creational design pattern which makes sure that only one single instance of a particular class is available during the runtime, and provides a global access to the single instance.

-> The main disadvantage of this implementation is that it is not safe for multi threaded environments. If separate threads of execution enter the instance property method at the same time, more than one instance of the Singleton object may be created.

-> The above approach ensures that only one instance is created and only when the instance is needed. Also variable is declared to be volatile to ensure that assignment  to the instance variable completes before the instance variable can be accessed. Lastly this approach uses a syncroot instance to lock on, rather than locking on the type itself, to avoid deadlocks.

9) Explain Builder Pattern ?
-> Builder pattern is useful when you need to create an object with lots of possible configuration options.
-> Builder is a creational design pattern that lets you produce different types and representations of an object using the same building process. Builder allows constructing complex objects step by step.
-> The builder pattern can be recognized in class, which has a single creational method and several methods to configure the resulting object. Builder methods often support chaining (sombuilder -> setValueA(1) -> setValueB(2) -> create()).

-> Declares steps required to build a product.
Concrete Builders
-> provide different implementations of the construction steps. Builders can also provide methods for fetching a construction result. This method can not be declared inside the builder interface, because builders may produce products that do not have the common interface. But if you are dealing with products from a single hierarchy, then this method can be safely described in the base interface.
-> Product is an object created as a result of construction. Builders can produce products that do not belong to the same class hierarchy or interface. It is a key difference between the Builder and other creational patterns.
-> constructs products using a Builder object. Usually, client assigns a builder instance to a director just once via constructor parameters. Then director uses that single builder object for all further construction. But there is an alternative when a builder is passed to the main production method of a director.

10) Explain Factory pattern ?

-> In factory pattern we create object without exposing the creation logic to the client and refer to newly created object using common interface.

11) What is Abstract Factory Pattern ?
-> In Abstract Factory Pattern an interface is responsible for creating a factory of related objects without explicitly specifying their classes. Each generated factory can give the objects as per the Factory Pattern.
-> Abstract Factory patterns work around a super factory which creates other factories. This factory is also called as factory of factories.

12) Explain Observer pattern ?

-> The observer pattern is a design pattern that defines a link between objects so that one object’s stat changes, all dependent objects are updated automatically. This pattern allows communication between objects in a loosely coupled manner.

-> The observer pattern defines a one-to-many dependency between a subject object and any number of observer objects, so that when the subject changes state, all its observer subjects are notified and updated automatically.

13) What is Repository Pattern ?
-> Is a data access pattern.
-> Separates persistence responsibility from business classes.
-> Enables 1) Single Responsibility Principle 2) Separation of Concerns 3) Testability
-> Separate repository for each entity in application

14) Explain Dependency Injection ?
-> Is a software design pattern that implements inversion of control for resolving dependencies.
-> DI is a style of object configuration in which object’s fields and references are set by an external framework.
-> In DI objects are given their dependencies at run time rather than compile time.
-> It helps to create loosely coupled classes.
-> There are three types of dependency injection
1) Constructor Injection
-> Dependencies are provided through a class constructor
2) Setter Injection
-> The client exposes a setter method that the injector uses to inject the dependency
3) Interface Injection
-> The dependency provides an injector method that will inject the dependency into any client passed to it. Clients must implement                      an interface that exposes a setter method that accepts the dependency

15) What are the advantages of Abstract classes over Interfaces ?
-> We can add a method to an Abstract base class without breaking all derived classes. If you add a method to an interface , you will break every single class that implements that interface.
-> Use an abstract class when there is a ‘IS-A’ relationship between classes. For example , Lion is an Animal, Cat is an Animal. So Animal can be an abstract class with common implementations like no of legs, tail etc.

16) What are the advantages of Interfaces over Abstract classes ?
-> The most obvious ‘shortcoming’ of Abstract classes, is that inheriting types can only inherit from one single abstract class. When it comes to interfaces, you can implement multiple interfaces.

17) Give an example for Abstract class design ?
-> Create an abstract class ‘AbstractRegularPolygon’

-> Create derived class ‘Triangle’ which inherits from ‘AbstractRegularPolygon’

-> Create instance of ‘Triangle’ of type ‘AbstractRegularPolygon’

18) Given an example of Interface based design ?
-> Create an interface

-> Create a concrete class which implements this interface.

-> Create instance of ‘Octagon’ of type ‘IRegularPolygon’



Leave a Reply

Your email address will not be published. Required fields are marked *