{"id":20875360,"url":"https://github.com/aershov24/design-patterns-interview-questions","last_synced_at":"2026-02-13T03:44:35.969Z","repository":{"id":99971296,"uuid":"235503363","full_name":"aershov24/design-patterns-interview-questions","owner":"aershov24","description":"🔴 Design Patterns Interview Questions and Answered to prepare for your next developer interview","archived":false,"fork":false,"pushed_at":"2020-01-24T03:40:10.000Z","size":12,"stargazers_count":4,"open_issues_count":0,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-19T09:12:17.154Z","etag":null,"topics":["design-pattern","design-patterns","designpatterns","interview-practice","interview-preparation","interview-questions","interview-test","oop-principles"],"latest_commit_sha":null,"homepage":"https://www.fullstack.cafe/Design%20Patterns","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aershov24.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-01-22T05:12:50.000Z","updated_at":"2025-01-18T17:00:25.000Z","dependencies_parsed_at":"2023-05-11T08:45:25.409Z","dependency_job_id":null,"html_url":"https://github.com/aershov24/design-patterns-interview-questions","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aershov24%2Fdesign-patterns-interview-questions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aershov24%2Fdesign-patterns-interview-questions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aershov24%2Fdesign-patterns-interview-questions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aershov24%2Fdesign-patterns-interview-questions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aershov24","download_url":"https://codeload.github.com/aershov24/design-patterns-interview-questions/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243249011,"owners_count":20260768,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["design-pattern","design-patterns","designpatterns","interview-practice","interview-preparation","interview-questions","interview-test","oop-principles"],"created_at":"2024-11-18T06:44:18.838Z","updated_at":"2026-02-13T03:44:30.946Z","avatar_url":"https://github.com/aershov24.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Design Patterns Interview Questions\n\nIn software engineering, a design pattern is a general repeatable solution to a commonly occurring problem in software design. A design pattern isn't a finished design that can be transformed directly into code. It is a description or template for how to solve a problem that can be used in many different situations.\n\n\u003e You could also find all the answers here 👉 https://www.fullstack.cafe/Design%20Patterns\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://www.fullstack.cafe\"\u003e\n  \u003cimg src=\"https://user-images.githubusercontent.com/13550565/73042889-e7533900-3e9d-11ea-94f2-b4a9e87cc018.png\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n\n## Q1: What are the main categories of Design Patterns? ⭐\n\n**Answer:**\n\nThe Design patterns can be classified into three main categories:\n\n* Creational Patterns\n* Behavioral Patterns\n* Functional Patterns\n\n🔗 **Source:** [www.educba.com](https://www.educba.com/design-pattern-interview-questions/)\n\n\n## Q2: What is Design Patterns and why anyone should use them? ⭐\n\n**Answer:**\n\nDesign patterns are a well-described solution to the most commonly encountered problems which occur during software development. \n\nDesign 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.\n\n🔗 **Source:** [www.educba.com](https://www.educba.com/design-pattern-interview-questions/)\n\n\n## Q3: What is a pattern? ⭐\n\n**Answer:**\n\n*Patterns* in programming are like recipes in cooking. They are not ready dishes, but instructions for slicing and dicing products, cooking them, serving them and so forth.\n\n**Pattern content**\nAs a rule, a pattern description consists of the following:\n\n* a problem that the pattern solves;\n* motivation for solving the the problem using the method suggested by the pattern;\n* structures of classes comprising the solution;\n* an example in one of the programming languages;\n* a description of the nuances of pattern implementation in various contexts;\nrelations with other patterns.\n\n🔗 **Source:** [refactoring.guru](https://refactoring.guru/design-patterns/what-is-pattern)\n\n\n## Q4: What is Singleton pattern? ⭐\n\n**Answer:**\n\n**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.\n\n\u003cdiv class=\"text-center\"\u003e\n\u003cimg src=\"https://upload.wikimedia.org/wikipedia/commons/thumb/f/fb/Singleton_UML_class_diagram.svg/220px-Singleton_UML_class_diagram.svg.png\" class=\"img-fluid\"/\u003e\n\u003c/div\u003e\n\n\n🔗 **Source:** [refactoring.guru](https://refactoring.guru/design-patterns/what-is-pattern)\n\n\n## Q5: What is Dependency Injection? ⭐⭐\n\n**Answer:**\n\n*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.\n\n*Dependency injection* makes it easier to change the behavior 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.\n\n🔗 **Source:** [Pro ASP.NET Core MVC 2](https://github.com/TechBookHunter/Free-CSharp-Books/blob/master/book/Pro%20ASP.NET%20Core%20MVC%202%20-%20Seventh%20Edition.pdf)\n\n\n## Q6: What is Inversion of Control? ⭐⭐\n\n**Answer:**\n\n\n*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. \n\nFor example, say your application has a text editor component and you want to provide spell checking. Your standard code would look something like this:\n```js\npublic class TextEditor {\n\n    private SpellChecker checker;\n\n    public TextEditor() {\n        this.checker = new SpellChecker();\n    }\n}\n```\nWhat we've done here creates a dependency between the TextEditor and the SpellChecker. In an IoC scenario we would instead do something like this:\n```js\npublic class TextEditor {\n\n    private IocSpellChecker checker;\n\n    public TextEditor(IocSpellChecker checker) {\n        this.checker = checker;\n    }\n}\n```\n\nYou have *inverted control* by handing the responsibility of instantiating the spell checker from the TextEditor class to the caller.\n\n```js\nSpellChecker sc = new SpellChecker; // dependency\nTextEditor textEditor = new TextEditor(sc);\n```\n\n\n🔗 **Source:** [stackoverflow.com](https://stackoverflow.com/questions/3058/what-is-inversion-of-control?page=1\u0026tab=votes#tab-top)\n\n\n## Q7: Name types of Design Patterns? ⭐⭐\n\n**Answer:**\n\nDesign patterns can be classified in three categories: Creational, Structural and Behavioral patterns.\n\n-   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.\n\n-   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.\n\n-   Behavioral Patterns - These design patterns are specifically concerned with communication between objects.\n\n🔗 **Source:** [tutorialspoint.com](https://www.tutorialspoint.com/design_pattern/design_pattern_interview_questions.htm)\n\n\n## Q8: What is Factory pattern? ⭐⭐\n\n**Answer:**\n\n**Factory pattern** is one of most used design pattern and comes under *creational* patterns category.\n\nIn Factory pattern, we create object without exposing the creation logic to the client and refer to newly created object using a *common interface*.\n\n\u003cdiv class=\"text-center\"\u003e\n\u003cimg src=\"https://www.tutorialspoint.com/design_pattern/images/factory_pattern_uml_diagram.jpg\" class=\"img-fluid\"/\u003e\n\u003c/div\u003e\n\n\u003cbr/\u003e\n**Pro's**:  \n\n*   Allows you to hide implementation of an application seam (the core interfaces that make up your application)\n*   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\n*   Allows you to change the design of your application more readily, this is known as loose coupling\n\n**Con's**  \n\n*   Makes code more difficult to read as all of your code is behind an abstraction that may in turn hide abstractions.\n*   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.\n\n🔗 **Source:** [tutorialspoint.com](https://www.tutorialspoint.com/design_pattern/design_pattern_interview_questions.htm)\n\n\n## Q9: Can we create a clone of a singleton object? ⭐⭐\n\n**Answer:**\n\nYesl, we can but the purpose of Singleton Object creation is to have single instance serving all requests. \n\n🔗 **Source:** [tutorialspoint.com](https://www.tutorialspoint.com/design_pattern/design_pattern_interview_questions.htm)\n\n\n## Q10: What is Builder pattern? ⭐⭐\n\n**Answer:**\n\n*Builder pattern* builds a complex object using simple objects and using a step by step approach. This builder is independent of other objects.\n\n\n\u003cdiv class=\"text-center\"/\u003e\n\u003cimg src=\"https://www.plantuml.com/plantuml/svg/TOux3i8m343tdC9ZE_G234YqIAo86mJ7WqMQLeupS7kSqY90iCJsU_4dtpZDNlm8MU-Hx1L6BMDqHfMHPvyK_12PQio0d-B8GgYJL1M-UgQ4GafzuHXe-O5NvunvfPeYTDtU4jZ14sukh2gy6LXhcset5jIcTG6s_cN7sROVcXP-yVuF7oh75p-HNYYNQDCV\" class=\"img-fluid\" style=\"max-width: 500px\" /\u003e\n\u003c/div\u003e\n\n*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.\n\nBuilder/Director pattern's steps invocations could be semantically presented by *method chaining* or so called *Fluent Interface* syntax. \n\n```js\nPizza pizza = new Pizza.Builder()\n                       .cheese(true)\n                       .pepperoni(true)\n                       .bacon(true)\n                       .build();\n```\n\n🔗 **Source:** [tutorialspoint.com](https://www.tutorialspoint.com/design_pattern/design_pattern_interview_questions.htm)\n\n\n## Q11: What is Filter pattern? ⭐⭐\n\n**Answer:**\n\n**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.\n\n**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.\n\n```js\nList\u003cLaptop\u003e laptops = LaptopFactory.manufactureInBulk();\nAndCriteria searchCriteria = new AndCriteria(\n  new HardDisk250GBFilter(), \n  new MacintoshFilter(), \n  new I5ProcessorFilter());\nList\u003cLaptop\u003e filteredLaptops = searchCriteria.meets(laptops);\n```\n\n🔗 **Source:** [tutorialspoint.com](https://www.tutorialspoint.com/design_pattern/design_pattern_interview_questions.htm)\n\n\n## Q12: What is Proxy pattern? ⭐⭐\n\n**Answer:**\n\nIn **proxy pattern**, a class represents functionality of another class. This type of design pattern comes under _structural_ pattern.\n\nIn proxy pattern, we create object having original object to interface its functionality to outer world.\n\n\u003cdiv class=\"text-center\"\u003e\n\u003cimg src=\"https://upload.wikimedia.org/wikipedia/commons/thumb/7/75/Proxy_pattern_diagram.svg/439px-Proxy_pattern_diagram.svg.png\" class=\"img-fluid\"/\u003e\n\u003c/div\u003e\n\n🔗 **Source:** [tutorialspoint.com](https://www.tutorialspoint.com/design_pattern/design_pattern_interview_questions.htm)\n\n\n## Q13: What is Iterator pattern? ⭐⭐\n\n**Answer:**\n\n**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.\n\n\u003cdiv class=\"text-center\"\u003e\n\u003cimg src=\"https://upload.wikimedia.org/wikipedia/commons/c/c5/W3sDesign_Iterator_Design_Pattern_UML.jpg\" class=\"img-fluid\"/\u003e\n\u003c/div\u003e\n\n🔗 **Source:** [tutorialspoint.com](https://www.tutorialspoint.com/design_pattern/design_pattern_interview_questions.htm)\n\n\n## Q14: What is State pattern? ⭐⭐\n\n**Answer:**\n\nIn **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.\n\n\u003cdiv class=\"text-center\"\u003e\n\u003cimg src=\"https://upload.wikimedia.org/wikipedia/commons/e/ec/W3sDesign_State_Design_Pattern_UML.jpg\" class=\"img-fluid\"/\u003e\n\u003c/div\u003e\n\n🔗 **Source:** [tutorialspoint.com](https://www.tutorialspoint.com/design_pattern/design_pattern_interview_questions.htm)\n\n\n## Q15: What is Null Object pattern? ⭐⭐\n\n**Answer:**\n\nIn **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.\n\nIn 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.\n\n\u003cdiv class=\"text-center\"\u003e\n\u003cimg src=\"https://www.tutorialspoint.com/design_pattern/images/null_pattern_uml_diagram.jpg\" class=\"img-fluid\"/\u003e\n\u003c/div\u003e\n\n\n🔗 **Source:** [tutorialspoint.com](https://www.tutorialspoint.com/design_pattern/design_pattern_interview_questions.htm)\n\n\n## Q16: What is Strategy pattern? ⭐⭐\n\n**Answer:**\n\nIn **Strategy pattern**, a class behavior or its algorithm can be changed at run time. This type of design pattern comes under _behavior_ pattern.\n\nIn 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.\n\n\u003cdiv class=\"text-center\"\u003e\n\u003cimg src=\"https://upload.wikimedia.org/wikipedia/commons/4/45/W3sDesign_Strategy_Design_Pattern_UML.jpg\" class=\"img-fluid\"/\u003e\n\u003c/div\u003e\n\n\n\n🔗 **Source:** [tutorialspoint.com](https://www.tutorialspoint.com/design_pattern/design_pattern_interview_questions.htm)\n\n\n## Q17: What is Template pattern? ⭐⭐\n\n**Answer:**\n\nIn **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.\n\n\u003cdiv class=\"text-center\"\u003e\n\u003cimg src=\"https://upload.wikimedia.org/wikipedia/commons/2/2a/W3sDesign_Template_Method_Design_Pattern_UML.jpg\" class=\"img-fluid\"/\u003e\n\u003c/div\u003e\n\n🔗 **Source:** [tutorialspoint.com](https://www.tutorialspoint.com/design_pattern/design_pattern_interview_questions.htm)\n\n\n## Q18: What is Memento pattern? ⭐⭐⭐\n\n See 👉 **[Answer](https://www.fullstack.cafe/Design%20Patterns)**\n\n\n## Q19: What is Abstract Factory pattern? ⭐⭐⭐\n\n See 👉 **[Answer](https://www.fullstack.cafe/Design%20Patterns)**\n\n\n## Q20: What are the difference between a static class and a singleton class? ⭐⭐⭐\n\n See 👉 **[Answer](https://www.fullstack.cafe/Design%20Patterns)**\n\n\n## Q21: What is Prototype pattern? ⭐⭐⭐\n\n See 👉 **[Answer](https://www.fullstack.cafe/Design%20Patterns)**\n\n\n## Q22: What is Adapter Pattern? ⭐⭐⭐\n\n See 👉 **[Answer](https://www.fullstack.cafe/Design%20Patterns)**\n\n\n## Q23: What is Bridge pattern? ⭐⭐⭐\n\n See 👉 **[Answer](https://www.fullstack.cafe/Design%20Patterns)**\n\n\n## Q24: When should I use composite design pattern? ⭐⭐⭐\n\n See 👉 **[Answer](https://www.fullstack.cafe/Design%20Patterns)**\n\n\n## Q25: What does “program to interfaces, not implementations” mean? ⭐⭐⭐\n\n See 👉 **[Answer](https://www.fullstack.cafe/Design%20Patterns)**\n\n\n## Q26: What is Decorator pattern? ⭐⭐⭐\n\n See 👉 **[Answer](https://www.fullstack.cafe/Design%20Patterns)**\n\n\n## Q27: What is Facade pattern? ⭐⭐⭐\n\n See 👉 **[Answer](https://www.fullstack.cafe/Design%20Patterns)**\n\n\n## Q28: Can you give any good explanation what is the difference between Proxy and Decorator? ⭐⭐⭐\n\n See 👉 **[Answer](https://www.fullstack.cafe/Design%20Patterns)**\n\n\n## Q29: What is the Chain of Responsibility pattern? ⭐⭐⭐\n\n See 👉 **[Answer](https://www.fullstack.cafe/Design%20Patterns)**\n\n\n## Q30: What is Command pattern? ⭐⭐⭐\n\n See 👉 **[Answer](https://www.fullstack.cafe/Design%20Patterns)**\n\n\n## Q31: What is Interpreter pattern? ⭐⭐⭐\n\n See 👉 **[Answer](https://www.fullstack.cafe/Design%20Patterns)**\n\n\n## Q32: What is Mediator pattern? ⭐⭐⭐\n\n See 👉 **[Answer](https://www.fullstack.cafe/Design%20Patterns)**\n\n\n## Q33: What is Observer pattern? ⭐⭐⭐\n\n See 👉 **[Answer](https://www.fullstack.cafe/Design%20Patterns)**\n\n\n## Q34: How is Bridge pattern is different from Adapter pattern? ⭐⭐⭐⭐\n\n See 👉 **[Answer](https://www.fullstack.cafe/Design%20Patterns)**\n\n\n## Q35: When would you use the Builder Pattern? Why not just use a Factory Pattern? ⭐⭐⭐⭐\n\n See 👉 **[Answer](https://www.fullstack.cafe/Design%20Patterns)**\n\n\n## Q36: What is Flyweight pattern? ⭐⭐⭐⭐\n\n See 👉 **[Answer](https://www.fullstack.cafe/Design%20Patterns)**\n\n\n## Q37: Why would I ever use a Chain of Responsibility over a Decorator? ⭐⭐⭐⭐\n\n See 👉 **[Answer](https://www.fullstack.cafe/Design%20Patterns)**\n\n\n## Q38: Explain usage of Service Locator Pattern ⭐⭐⭐⭐\n\n See 👉 **[Answer](https://www.fullstack.cafe/Design%20Patterns)**\n\n\n## Q39: What is the difference between Strategy design pattern and State design pattern? ⭐⭐⭐⭐\n\n See 👉 **[Answer](https://www.fullstack.cafe/Design%20Patterns)**\n\n\n## Q40: Explain what is Composition over inheritance? ⭐⭐⭐⭐\n\n See 👉 **[Answer](https://www.fullstack.cafe/Design%20Patterns)**\n\n\n## Q41: Explain difference between the Facade, Proxy, Adapter and Decorator design patterns? ⭐⭐⭐⭐⭐\n\n See 👉 **[Answer](https://www.fullstack.cafe/Design%20Patterns)**\n\n\n## Q42: What's the difference between the Dependency Injection and Service Locator patterns? ⭐⭐⭐⭐⭐\n\n See 👉 **[Answer](https://www.fullstack.cafe/Design%20Patterns)**\n\n\n## Q43: Could you explain the difference between Façade vs. Mediator? ⭐⭐⭐⭐⭐\n\n See 👉 **[Answer](https://www.fullstack.cafe/Design%20Patterns)**\n\n\n## Q44: What is the difference between the template patterns and the strategy pattern? ⭐⭐⭐⭐⭐\n\n See 👉 **[Answer](https://www.fullstack.cafe/Design%20Patterns)**\n\n\n## Q45: Could you explain what is the \"deadly diamond of death\"? ⭐⭐⭐⭐⭐\n\n See 👉 **[Answer](https://www.fullstack.cafe/Design%20Patterns)**\n\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faershov24%2Fdesign-patterns-interview-questions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faershov24%2Fdesign-patterns-interview-questions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faershov24%2Fdesign-patterns-interview-questions/lists"}