Tech Point Fundamentals

Friday, March 4, 2022

Design Patterns Interview Questions - Part 01

Design Patterns Interview Questions and Answers - Part 01

design-pattern-interview-questions

In Software Industry the Design Patterns and Principles are always followed. So this is the most common topic for the interview. In this article, we will see the most frequently asked 90+ Design Patterns and Principles Interview Questions with Answers

Please visit our YouTube Channel for Interviews and other videos by below link:


Please read the complete C# Interview Questions and Answers article series here.



Introduction


This is the 1st part of this Design Patterns and Principles Interview Questions and Answers article series. Each part will contain eight Design Pattern Interview Questions. 

Please read all the Design Patterns and Principles Interview Questions list here.





Design Patterns Interview Questions and Answers - Part 01


Q01. What is Design Pattern and why Design Patterns are important to use? 

A design pattern is a general reusable solution to a commonly occurring problem in software design. It is not a finished design that can be transformed directly into source or machine code. Rather, it is a description or template for how to solve a problem that can be used in many different situations.

Design patterns are solutions to general problems that software developers faced during software development. These solutions were obtained by trial and error by numerous software developers over quite a substantial period of time. Design patterns are formalized best practices that the programmer can use to solve common problems when designing an application or system.



A design pattern is a concept or a receipt for how to get a specific problem done. They have solved many software architecture issues with different pre-defined designs.A pattern is a best practice, a recipe, a time-tested solution to a recurring problem that's proved to work and to be the best one among to choose.

Design patterns can speed up the development process by providing tested, proven development paradigms. Effective software design requires considering issues that may not become visible until later in the implementation. Reusing design patterns helps to prevent subtle issues that can cause major problems and improves code readability for coders and architects familiar with the patterns.

Object-oriented design patterns typically show relationships and interactions between classes or objects, without specifying the final application classes or objects that are involved.  There are different types of design patterns like Creational Patterns, Structural Patterns, and Behavioral Patterns.
 



Q02. What is Design Framework? How it is different from the Design Pattern?

A framework is the basic structure of something. A framework creates the basic structure that gives focus and support to the problem you’re trying to solve. They provide a set of ideas or facts for the project.  A design framework is a simple visual structure that helps organize the information and ideas of a problem so you can work on it more effectively. 

A framework is a platform that you can use to build applications. It provides the foundation for developers to create their software as it necessarily imposes an architectural paradigm and even includes a development philosophy. The frameworks include predefined elements like classes and functions that can handle common software tasks like processing input and interacting with systems. 



There are different components in a framework including the logic within the frameworks themselves, as all of them provide architectural structures that predefine how the different parts of an application will work together.  A framework also provides generic functionality, built-in solutions to common development tasks and routines, code structures, and the development philosophy as well. A framework is a set of related classes to perform a certain task.

A Framework is a code ready for use, usually packaged in a way that makes creating an application much easier. A framework is a library that provides a foundation layer to use to build applications without writing everything from scratch.

A design pattern is a standard solution to a well-known design problem. There are different types of frameworks are available for example ASP.NET/ASP.NET Core,  Angular, Vue, Spring, React Native, Laravel, Ruby on Rails, Symfony, Bootstrap, Spark, Xamarin, jQuery, Flutter, etc.




Q03. What is the difference between Design Pattern and Design Framework?

Both Design Pattern and Design Framework are two different things even though they both solve a software architecture problem.

A design pattern is a concept or a receipt for how to get a specific problem done, they solve many software architecture issues. A pattern is a best practice, a recipe, a time-tested solution to a recurring problem that's proved to work and to be the best one among to choose.

On the other hand, a design framework is an actual implementation of design patterns. A design framework is a code ready for use, usually packaged in a way that makes creating an application much easier. The framework contains a set of libraries that provides a foundation layer to use to build applications without writing everything from scratch.



Design patterns are smaller architectural elements than frameworks. A typical framework contains several design patterns, but the reverse is never true. Design patterns are less specialized than frameworks. Frameworks always have a particular application domain. 

Design patterns are schematic descriptions of reusable designs that are not concrete programs and that are language-independent. On the other hand, frameworks are compilable programs written in a specific programming language and often contain abstract classes and interfaces.

Design patterns are more abstract than frameworks. Frameworks can be embodied in code. A strength of frameworks is that they can be written down in any programming language and not only studied but executed and reused directly.




Q04. What is Design Principle? What is the difference between Design Patterns and Design Principles?

Design principles are high-level guidelines to design better software applications. Design principles are the guidelines that help us improve the quality of our application. 

They do not provide any implementation guidelines and are not bound to any programming language as well. These Design principles go beyond the core object-oriented concepts like Inheritance, Encapsulation, Abstraction, and Polymorphism.

Software design principles are concerned with providing means to handle the complexity of the design process effectively. On the other hand, Design Pattern provides low-level solutions related to the implementation, of commonly occurring object-oriented problems.

Design Principles are general guidelines that can guide your class structure and relationships. On the other hand, Design Patterns are proven solutions that solve commonly reoccurring problems.  However, most of the practical implementations of these design principles are mostly done using one or more design patterns.

There are so many design principles like SOLID Principles, GRAPS Principles, DRY, KISS, YAGNI, AHA, etc.



Q05. What is Architectural Pattern? What is the difference between Architectural Patterns and Design Patterns?

Architectural styles tell us how to organize our code. It’s the highest level of granularity and it specifies layers, high-level modules of the application and how those modules and layers interact with each other, the relations between them.

Architectural Pattern is a recurring solution to a recurring problem. Architecture is the overall structure of software. In the case of Architectural Patterns, they solve the problems related to the Architectural Style.

Architectural Patterns have an extensive impact on the code base, most often impacting the whole application either horizontally (ie. how to structure the code inside a layer) or vertically (ie. how a request is processed from the outer layers into the inner layers and back).



The Architectural Style can be implemented in different ways, with a specific technical environment, specific policies, frameworks, or practices. 

Design Patterns differ from Architectural Patterns in their scope, they are more localized, they have less impact on the code base, they impact a specific section of the codebase.

For example Monolithic Application Architecture, Three-Tier Architecture,  Service-Oriented Architecture, Client-Server Architecture, Event-Driven Architecture, Publisher-Subscribe Architecture, Layered Architecture,  MVC Architecture, etc.



Q06. What is the N-Layer Architecture? Why layering your application is important?

The Layers refer to the logical separation of the application code. Logical layers help us to organize our code in a better way.   N-Layers refers to the internal architecture of your component. 

Layered architecture focuses on the grouping of related functionality within an application into distinct layers that are stacked vertically on top of each other.  The Layers refer to the logical separation of the application code. Logical layers help us to organize our code in a better way. 

Layers are a way to separate responsibilities and manage dependencies. Each layer has a specific responsibility. A higher layer can use services in a lower layer, but not the other way around. 

For example Presentation Layer, Business Logic Layer, Data Access Layer of traditional 3 layer architecture. The three layers reside in their own projects, maybe in 3 different projects or even more. 



Advantages:

1. Layered architecture increases flexibility, maintainability, and scalability. 
2. Layered architecture somehow follows the separation of concerns because we separate the user interface (i.e. presentation layer) from the business logic and the business logic from the data access logic layer.
3. The layered architecture allows us to reuse the same components in multiple applications. 
4. The layered architecture enables teams to work on different parts of the application parallel with minimal dependencies on other teams.
5. Different components of the application can be independently deployed, maintained, and updated, on different time schedules.
6. Layered architecture also makes it possible to configure different levels of security to different components deployed on different machines. So Layered architecture, enables us to secure portions of the application behind the firewall and make other components accessible from the Internet.



Q07. What is N-Tire Architecture? What is the difference between N-Tire Architecture and N-Layer Architecture?

N-Tier and N-Layer are entirely different concepts. N-Tier refers to the actual n system components of your application. On the other hand, N-Layers refers to the internal architecture of your component. 

N-Tier architecture usually has at least three separate logical parts, each located on a separate physical server. Each tier is responsible for specific functionality. N-Layers of application may reside on the same physical computer (same tier) and the components in each layer communicate with the components of other layers by well-defined interfaces.

Layered architecture focuses on the grouping of related functionality within an application into distinct layers that are stacked vertically on top of each other.  The Layers refer to the logical separation of the application code. Logical layers help us to organize our code in a better way. 



Tiers indicate a physical separation of components, which may mean different assemblies on the same server or multiple servers. While layers refer to a logical separation of components, such as having distinct namespaces and classes for the Database Access Layer (DAL), Business Logic Layer (BLL), and User Interface Layer (UIL).

 An N-tier architecture divides an application into logical layers and physical tiers. Layers are a way to separate responsibilities and manage dependencies. Each layer has a specific responsibility. A higher layer can use services in a lower layer, but not the other way around. Tiers are physically separated, running on separate machines. A tier can call to another tier directly, or use asynchronous messaging (message queue). 

A traditional three-tier application has a presentation tier, a middle tier, and a database tier. The middle tier is optional. More complex applications can have more than three tiers. 



Q08. What is the MVC Pattern? How MVC is different from 3-Layer Architecture or 3-Tire Architecture? 

MVC is known as an architectural pattern that divides the application into three logical parts: the Model part, the View, and the Controller.  MVC is an architectural pattern which means it rules the whole architecture of the applications.

Model is the lowest level that is responsible for maintaining data. It responds to the controller requests because the controller never talks to the database by itself. 

The UI and data representation are done by the view component. It actually generates UI or user interface for the user. Views and models can not talk directly.



The controller is the component that enables the interconnection between the views and the model so it acts as an intermediary.

Trygve Reenskaug invented MVC. The first reports on MVC were written when he was visiting a scientist at PARC (Xerox Palo Alto Research Laboratory) in 1978/79. 

Since the MVC pattern was invented before web browsers, initially was used as an architectural pattern for graphical user interfaces(GUI). Currently MVC it’s used for designing web applications. 

Some web frameworks that use the MVC concept: Ruby on Rails, Laravel, Zend framework, CherryPy, Symphony, etc.



Advantage:

  1. MVC follows the separation of concerns as it separates the user interface from business logic and business logic.
  2. In MVC Components are reusable so it doesn't allow us to repeat ourselves.
  3. The MVC architecture helped to test components independently.
  4. MVC applications are easy to maintain.
  5. Different components of the application in MVC can be independently deployed and maintained.



MVC vs N-Layer Architecture:

MVC is an inbuilt framework while N-Layer is a user-defined system where the user has to create and define each and every layer and their interaction as well. However, we can use the MVC within the N-Layer Architecture.

MVC abstracts away the details of how the architecture of an app is implemented. N-tier just refers to the physical structure of an implementation. 


To Be Continued Part-02...


Recommended Articles






Thanks for visiting this page. Please follow and join us on LinkedInFacebookTelegramQuoraYouTubeTwitterPinterestTumblerVK, and WhatsApp for regular updates.

    

No comments:

Post a Comment

Please do not enter any HTML. JavaScript or spam link in the comment box.