Design Patterns

Skill
Computer Science

Top 250 Design Patterns Interview Questions and Answers 2024

250 questions found

Updated 11 Dec 2024

Q1. What are the objects generated after TMG is created

Ans.

Objects generated after TMG creation in SAP ABAP

  • After creating a TMG (Table Maintenance Generator), a function group is generated.

  • The function group contains function modules for maintenance screens, list displays, and authorization checks.

  • A maintenance view is also generated, which is used to maintain the table data.

  • A maintenance dialog is created, which is used to display the maintenance screens.

  • A maintenance object is generated, which is used to store the maintenance dialo...read more

View 1 answer
Frequently asked in

Q2. What is singleton design patterns and how to create a singleton class

Ans.

Singleton design pattern ensures only one instance of a class is created and provides global access to it.

  • Create a private constructor to prevent direct instantiation

  • Create a private static instance of the class

  • Provide a public static method to access the instance

  • Ensure thread safety by using synchronized keyword or static initializer

  • Examples: Logger, Configuration Manager, Database Connection

Add your answer

Q3. what is the difference between factory and service

Ans.

A factory is responsible for creating and managing objects, while a service is responsible for providing specific functionality or performing tasks.

  • A factory is used to create and initialize objects, often based on certain parameters or configurations.

  • A service is a component that provides specific functionality or performs tasks for other components or systems.

  • Factories are commonly used in object-oriented programming to encapsulate object creation logic.

  • Services are often u...read more

Add your answer

Q4. Design a lift system. OOPs concept

Ans.

Design a lift system using OOPs concepts.

  • Create a Lift class with methods like moveUp(), moveDown(), openDoor(), closeDoor()

  • Create a Floor class with methods like requestLift()

  • Use inheritance to create different types of lifts like passenger lift, cargo lift, etc.

  • Use encapsulation to hide the internal workings of the lift system from the outside world.

  • Use polymorphism to allow different types of lifts to respond differently to the same method calls.

Add your answer
Are these interview questions helpful?

Q5. How will you restrict the instantiation of a class to a single object?

Ans.

By implementing the Singleton design pattern, we can restrict the instantiation of a class to a single object.

  • Implement a private constructor in the class to prevent external instantiation.

  • Create a static method that returns the single instance of the class.

  • Use a private static variable to hold the single instance of the class.

  • Ensure thread-safety by using synchronization or double-checked locking if necessary.

View 1 answer

Q6. How does MVVM structure work?

Ans.

MVVM is a design pattern that separates UI logic from business logic.

  • Model represents the data and business logic

  • View displays the UI and user interactions

  • ViewModel acts as a mediator between Model and View

  • ViewModel exposes data and commands to the View

  • View binds to ViewModel properties and commands

  • Changes in ViewModel update the View and vice versa

Add your answer
Frequently asked in
Share interview questions and help millions of jobseekers 🌟
Q7. Design Question

Snake game

Ans.

Design a snake game

  • Use a 2D array to represent the game board

  • Keep track of the snake's position and direction

  • Handle user input to change the snake's direction

  • Update the snake's position and check for collisions with walls or itself

  • Add food to the board and handle eating it to grow the snake

  • Keep track of the score and display it to the player

View 1 answer
Frequently asked in

Q8. 2.what is singleton pattern

Ans.

Singleton pattern is a design pattern that restricts the instantiation of a class to one object.

  • Used when only one instance of a class is needed throughout the application

  • Provides a global point of access to the instance

  • Implemented using a private constructor and a static method to return the instance

  • Example: Database connection, Logger, Configuration settings

Add your answer
Frequently asked in

Design Patterns Jobs

Application Developer: SAP ABAP HANA 2-4 years
IBM India Pvt. Limited
4.1
₹ 4 L/yr - ₹ 13 L/yr
(AmbitionBox estimate)
Kolkata
Package Consultant: Oracle Retail 5-8 years
IBM India Pvt. Limited
4.1
₹ 8 L/yr - ₹ 32 L/yr
(AmbitionBox estimate)
Bangalore / Bengaluru
Application Developer: SAP ABAP HANA 2-4 years
IBM India Pvt. Limited
4.1
₹ 3 L/yr - ₹ 25 L/yr
(AmbitionBox estimate)
Bangalore / Bengaluru

Q9. What is a Factory design pattern? How do you implement that?

Ans.

Factory design pattern is a creational pattern that provides an interface for creating objects in a superclass, but allows subclasses to alter the type of objects that will be created.

  • Factory pattern is used when we have a superclass with multiple subclasses and based on input, we need to return one of the subclass.

  • It provides a way to delegate the instantiation logic to child classes.

  • Example: java.util.Calendar, java.util.ResourceBundle, java.text.NumberFormat, etc.

Add your answer

Q10. What is use of factory

Ans.

A factory is used to create objects of a specific class without exposing the creation logic to the client.

  • Factories provide a way to create objects without exposing the creation logic to the client.

  • They can be used to create objects of a specific class or a group of related classes.

  • Factories can be used to implement the Singleton pattern, where only one instance of a class is created.

  • They can also be used to implement the Abstract Factory pattern, where a family of related ob...read more

Add your answer

Q11. Explain microservices and design patterns used in your project

Ans.

Microservices are a software architectural style that structures an application as a collection of loosely coupled services.

  • Microservices break down a large application into smaller, independent services that can be developed, deployed, and scaled independently.

  • Common design patterns used in microservices architecture include Service Registry, Circuit Breaker, API Gateway, and Event Sourcing.

  • Service Registry pattern helps services locate and communicate with each other.

  • Circui...read more

Add your answer

Q12. what is observer pattern

Ans.

Observer pattern is a design pattern in which an object maintains a list of its dependents and notifies them automatically of any state changes.

  • Also known as publish-subscribe pattern

  • Used in event-driven systems

  • Allows loose coupling between objects

  • Example: A weather station broadcasts weather updates to multiple displays

  • Example: A stock market ticker notifies multiple investors of stock price changes

Add your answer
Frequently asked in

Q13. What is design How to use

Ans.

Design is the process of creating a plan or solution to address a specific problem or need.

  • Design involves identifying a problem or need

  • Creating a plan or solution to address the problem or need

  • Implementing the plan or solution through various tools and techniques

  • Evaluating the effectiveness of the design and making improvements if necessary

Add your answer

Q14. Explain MVC pattern

Ans.

MVC pattern is a software design pattern that separates an application into three main components: Model, View, and Controller.

  • Model represents the data and business logic of the application

  • View represents the user interface

  • Controller acts as an intermediary between Model and View, handling user input and updating the Model accordingly

  • Example: In a web application, the Model could be a database, the View could be the HTML/CSS for the UI, and the Controller could be the server...read more

Add your answer
Frequently asked in

Q15. Difference between architectural patterns and design patterns.

Ans.

Architectural patterns define the overall structure and organization of a system, while design patterns provide solutions to specific design problems within the system.

  • Architectural patterns focus on high-level decisions about the system's structure, components, and interactions.

  • Design patterns address lower-level design decisions and provide reusable solutions to common design problems.

  • Architectural patterns are concerned with system-wide concerns like scalability, security,...read more

View 1 answer
Frequently asked in

Q16. What is meant by Repository Pattern

Ans.

Repository Pattern is a design pattern that separates data access logic from business logic.

  • It provides a way to access data from a data source without exposing the underlying database or data store.

  • It helps in achieving separation of concerns and makes the code more modular and testable.

  • It can be implemented using interfaces and classes to define a set of methods for data access.

  • Examples include Entity Framework in .NET, Hibernate in Java, and Django ORM in Python.

Add your answer

Q17. Design repository pattern using EF core

Ans.

Repository pattern using EF core for data access layer

  • Create an interface for the repository with generic CRUD methods

  • Implement the repository interface with EF core for data access

  • Use dependency injection to inject the repository into services

  • Separate concerns by having repositories handle data access logic

Add your answer

Q18. what design pattern are there in java and on which pattern have you worked.

Ans.

Java has several design patterns such as Singleton, Factory, Observer, Decorator, etc.

  • Singleton pattern ensures that only one instance of a class is created

  • Factory pattern provides an interface for creating objects in a superclass, but allows subclasses to alter the type of objects that will be created

  • Observer pattern defines a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically

  • Decorator patte...read more

Add your answer
Frequently asked in

Q19. design a cab booking system using oops

Ans.

A cab booking system designed using OOP principles

  • Create classes for Cab, Customer, Driver, and Booking

  • Use inheritance and polymorphism to handle different types of cabs and bookings

  • Implement methods for booking a cab, assigning a driver, and calculating fare

  • Use encapsulation to protect data and ensure data integrity

Add your answer

Q20. 1. What is design pattern and it's types and solid patterns.

Ans.

Design patterns are reusable solutions to common software design problems. They include creational, structural, and behavioral patterns.

  • Design patterns are reusable solutions to common software design problems.

  • They provide proven solutions to recurring design problems.

  • Design patterns can be categorized into creational, structural, and behavioral patterns.

  • Creational patterns deal with object creation mechanisms.

  • Structural patterns focus on class and object composition.

  • Behavior...read more

View 1 answer

Q21. Design Snake game

Ans.

Snake game is a classic arcade game where a player controls a snake to eat food and grow longer while avoiding collisions with walls and itself.

  • Create a grid-based game board where the snake can move in four directions (up, down, left, right)

  • Generate food randomly on the board for the snake to eat and grow in length

  • Implement collision detection to check if the snake hits the walls or itself

  • Update the game state continuously based on user input and game logic

  • Keep track of the ...read more

Add your answer
Frequently asked in

Q22. 1 Explain oops concept 2 Design patterns

Ans.

OOPs is a programming paradigm based on the concept of objects that interact with each other.

  • OOPs stands for Object-Oriented Programming.

  • It focuses on the creation of objects that have properties and methods.

  • Encapsulation, Inheritance, Polymorphism, and Abstraction are the four main pillars of OOPs.

  • Design patterns are reusable solutions to common software problems.

  • Some popular design patterns are Singleton, Factory, Observer, and Decorator.

Add your answer
Frequently asked in

Q23. Design a basic google doc editor with oops.

Ans.

A basic Google Doc editor designed using OOP principles.

  • Create a Document class to represent the Google Doc

  • Include methods for editing text, adding images, and formatting

  • Use classes like Text, Image, and FormattingOptions for different elements

  • Implement features like undo/redo functionality and collaboration tools

Add your answer

Q24. create Observer class

Ans.

Create an Observer class

  • Observer class is used to notify changes to multiple objects

  • It maintains a list of objects that need to be notified

  • It has methods to add, remove and notify observers

  • Example: Weather station notifying multiple displays

Add your answer

Q25. Explain mostly used design patterns in JavaScript

Ans.

The mostly used design patterns in JavaScript are Module, Observer, Singleton, Factory, and Prototype.

  • Module pattern helps to keep the code organized and maintainable.

  • Observer pattern is used for event handling and notification.

  • Singleton pattern restricts the instantiation of a class to a single instance.

  • Factory pattern provides an interface for creating objects in a superclass, but allows subclasses to alter the type of objects that will be created.

  • Prototype pattern creates ...read more

Add your answer
Frequently asked in

Q26. What design pattern used in angular

Ans.

The design pattern commonly used in Angular is the Observer pattern.

  • The Observer pattern is used to establish a one-to-many dependency between objects.

  • In Angular, Observables are used to implement the Observer pattern for handling asynchronous data streams.

  • Components in Angular often use Observables to subscribe to changes and react accordingly.

Add your answer

Q27. design for a date picker in javascript

Ans.

A date picker in JavaScript allows users to select a date from a calendar interface.

  • Use HTML input element with type 'date' for modern browsers

  • For older browsers, use a JavaScript library like jQuery UI Datepicker

  • Implement validation to ensure selected date is within acceptable range

Add your answer

Q28. What are design patterns, and have you implemented any of the design pattern in your previous project, can you explain?

Ans.

Design patterns are reusable solutions to common software design problems.

  • Design patterns help in creating flexible, reusable, and maintainable code.

  • Examples of design patterns include Singleton, Factory, Observer, and Decorator.

  • I have implemented the Singleton pattern in my previous project to ensure only one instance of a class is created.

  • I have also used the Factory pattern to create objects without exposing the instantiation logic to the client code.

Add your answer
Frequently asked in

Q29. Difference between design pattern and design principle

Ans.

Design patterns are reusable solutions to common problems in software design, while design principles are guidelines to follow for good design practices.

  • Design patterns provide specific solutions to recurring problems in software design, such as Singleton, Factory, and Observer patterns.

  • Design principles are general guidelines that help in designing software that is maintainable, scalable, and flexible, such as SOLID principles and DRY (Don't Repeat Yourself) principle.

  • Design...read more

Add your answer
Frequently asked in

Q30. What Micro services design pattern used

Ans.

The microservices design pattern used is the API Gateway pattern.

  • API Gateway pattern is used to provide a single entry point for clients to access multiple microservices.

  • It helps in routing requests, load balancing, authentication, and monitoring.

  • Examples include Netflix Zuul and Amazon API Gateway.

Add your answer
Frequently asked in

Q31. What is the use of relay in DI

Ans.

Relays in Dependency Injection are used to control the creation and lifecycle of objects.

  • Relays help in decoupling the creation of objects from their usage.

  • They can be used to provide different implementations of an interface based on certain conditions.

  • Relays can also be used for lazy loading of objects to improve performance.

  • They help in managing the dependencies of objects in a flexible and modular way.

Add your answer

Q32. Difference between Static and Singleton

Ans.

Static is a keyword used to declare a variable or method that belongs to the class. Singleton is a design pattern that restricts the instantiation of a class to one object.

  • Static members are accessed using the class name, while Singleton objects are accessed using a getInstance() method.

  • Static members are shared among all instances of a class, while Singleton objects are unique.

  • Static members are initialized when the class is loaded, while Singleton objects are initialized wh...read more

Add your answer

Q33. What is Singleton class and is circuit breaker pattern.

Ans.

Singleton class is a design pattern that restricts the instantiation of a class to one object, while circuit breaker pattern is a design pattern used in software development to prevent cascading failures.

  • Singleton class ensures that a class has only one instance and provides a global point of access to it.

  • Circuit breaker pattern is used to detect failures and prevent them from causing further damage by temporarily stopping the execution of a function or service.

  • Example of Sin...read more

Add your answer

Q34. Which microservice design pattern did you implement to break your monolith to microservice and why?

Ans.

I implemented the API Gateway pattern to break the monolith into microservices.

  • API Gateway pattern acts as a single entry point for clients to access multiple microservices.

  • It helps in decoupling the client from individual microservices.

  • API Gateway handles authentication, routing, load balancing, and caching.

  • It simplifies the client-side code by providing a unified interface.

  • Example: Netflix's Zuul acts as an API Gateway for their microservices architecture.

View 1 answer

Q35. Difference between factory and builder

Ans.

Factory creates objects without specifying the exact class, while builder constructs complex objects step by step.

  • Factory pattern creates objects without specifying the exact class to create, using a common interface.

  • Builder pattern constructs complex objects step by step, allowing different representations of an object to be created using the same construction process.

  • Factory pattern is used when the creation process is simple and does not require many parameters, while buil...read more

Add your answer
Frequently asked in

Q36. Explain the Builder pattern

Ans.

Builder pattern is a creational design pattern that separates the construction of a complex object from its representation.

  • Separates the construction of a complex object from its representation

  • Allows the same construction process to create different representations

  • Helps in creating objects step by step

Add your answer
Frequently asked in

Q37. Which class is used in Factory method?

Ans.

The class used in Factory method is the Factory class.

  • The Factory class is responsible for creating objects of different classes based on the input parameters.

  • It is a creational design pattern.

  • The Factory method is a static method that returns an object of the class that it belongs to.

  • Example: Class CarFactory has a static method createCar() that returns an object of Car class.

  • The Factory method is used to encapsulate object creation logic and make it more flexible and reusab...read more

Add your answer

Q38. What is visitor pattern?

Ans.

Visitor pattern is a design pattern where a visitor class is used to perform operations on elements of a data structure.

  • Visitor pattern allows adding new operations to existing classes without modifying them

  • It separates the algorithm from the object structure on which it operates

  • Commonly used in compilers, interpreters, and other complex systems

Add your answer
Frequently asked in

Q39. What are diff design patterns in sql

Ans.

Design patterns in SQL are reusable solutions to common problems encountered in database design and development.

  • Singleton Pattern: Ensures a class has only one instance and provides a global point of access to it.

  • Factory Pattern: Creates objects without specifying the exact class of object that will be created.

  • Repository Pattern: Separates the logic that retrieves data from a data source from the business logic that acts on the data.

  • Decorator Pattern: Allows behavior to be ad...read more

Add your answer

Q40. Design an analytical framework for IPL bidding sustem

Ans.

An analytical framework for IPL bidding system

  • Identify key performance indicators (KPIs) such as player performance, team performance, market value, etc.

  • Collect and analyze historical data on player and team performance, auction prices, and market trends

  • Develop predictive models using machine learning algorithms to forecast player and team performance and auction prices

  • Use the models to simulate different bidding scenarios and optimize team selection and budget allocation

  • Cont...read more

Add your answer

Q41. DO you know about the design pattern in C++

Ans.

Design patterns in C++ are reusable solutions to common problems in software design.

  • Design patterns help in creating flexible, maintainable, and scalable code.

  • Examples of design patterns in C++ include Singleton, Factory, Observer, and Strategy.

  • Each design pattern has its own purpose and can be applied in different scenarios.

  • Understanding design patterns can improve code quality and efficiency.

Add your answer

Q42. 1. What is service container. 2. Which pattern used in laravel?

Ans.

Service container is a tool in Laravel that manages class dependencies and performs dependency injection.

  • Service container in Laravel is used to bind classes and interfaces, resolve dependencies, and manage object instances.

  • It allows for inversion of control and dependency injection, making it easier to manage dependencies in the application.

  • Service container is accessed using the `app()` helper function or by type-hinting in controller constructors.

  • It helps in decoupling cla...read more

Add your answer

Q43. Design a vending machine

Ans.

Design a vending machine that dispenses snacks and drinks.

  • Include a user interface with buttons for selecting items

  • Have a payment system that accepts cash, credit cards, and mobile payments

  • Implement a system for restocking items and tracking inventory levels

Add your answer

Q44. What are the design patten we use in iOS?

Ans.

iOS design patterns include MVC, MVVM, Singleton, Factory, and Observer.

  • MVC separates data, view, and controller logic

  • MVVM adds a view model to handle data binding

  • Singleton ensures only one instance of a class exists

  • Factory creates objects without exposing the creation logic

  • Observer allows objects to be notified of changes in other objects

Add your answer

Q45. Design LLD for factory pattern

Ans.

Factory pattern is a creational design pattern that provides an interface for creating objects in a superclass, but allows subclasses to alter the type of objects that will be created.

  • Create an interface or abstract class to define the factory method

  • Create concrete classes that implement the interface or extend the abstract class

  • Factory class should have a method that returns an object of the interface type based on input parameters

Add your answer
Frequently asked in

Q46. DESIGN LRU CACHE

Ans.

LRU cache is a data structure that stores the most recently used items.

  • Use a doubly linked list to keep track of the order of items based on their usage.

  • Use a hashmap to quickly access items in the cache.

  • When a new item is accessed, move it to the front of the linked list.

  • If the cache is full, remove the least recently used item from the end of the linked list.

Add your answer

Q47. What is Decorator design pattern

Ans.

Decorator pattern adds behavior to an object dynamically without affecting its existing behavior.

  • It is a structural pattern

  • It involves a component interface, concrete component, decorator interface, and concrete decorator

  • Decorators wrap around components to add new behavior

  • It allows for flexible and dynamic behavior modification

  • Example: Java I/O streams use decorator pattern

Add your answer
Frequently asked in

Q48. Compare 2 nested JSON objects and find the property/subproperty which is the difference Implementation of Builder design pattern

Ans.

Compare 2 nested JSON objects and find the property/subproperty which is the difference

  • Parse both JSON objects and compare each property/subproperty recursively

  • Use a recursive function to traverse the JSON objects

  • When a difference is found, store the property/subproperty and its value

  • Return the stored differences as a JSON object

Add your answer

Q49. Design question- how to design a fail safe iterator

Ans.

A fail-safe iterator should handle exceptions and errors gracefully without crashing the program.

  • Use try-catch blocks to handle exceptions and errors

  • Implement a hasNext() method to check if there are more elements to iterate over

  • Use a current pointer to keep track of the current element being iterated over

  • Ensure that the iterator is thread-safe

  • Provide clear documentation on how to use the iterator

Add your answer
Frequently asked in

Q50. Design a library to log drop-rate in form fields.

Ans.

Design a library to log drop-rate in form fields.

  • Create a function to track changes in form fields

  • Implement a mechanism to calculate drop-rate based on user interactions

  • Store drop-rate data in a database for analysis

Add your answer
Frequently asked in

Q51. Design a mood 3 counter

Ans.

A mood 3 counter is a device that tracks and displays the user's mood on a scale of 1-3.

  • Design a simple interface with 3 buttons for the user to input their mood (happy, neutral, sad)

  • Include a display screen to show the current mood level

  • Implement a reset button to clear the mood counter

  • Consider adding a visual indicator such as colored LEDs for each mood level

Add your answer
Frequently asked in

Q52. Explain design patterns in Unity

Ans.

Design patterns in Unity are reusable solutions to common problems in game development.

  • Design patterns help in organizing code, improving code readability, and promoting code reusability.

  • Examples of design patterns in Unity include Singleton, Observer, Factory, and State.

  • Singleton pattern ensures a class has only one instance and provides a global point of access to it.

  • Observer pattern defines a one-to-many dependency between objects so that when one object changes state, all...read more

Add your answer

Q53. Explain object oriented concepts and design in detail.

Ans.

Object-oriented concepts and design involve creating classes and objects that encapsulate data and behavior.

  • Object-oriented programming is based on the principles of encapsulation, inheritance, and polymorphism.

  • Classes are used to define objects, which contain data and methods that operate on that data.

  • Inheritance allows classes to inherit properties and methods from other classes, while polymorphism allows objects to take on multiple forms.

  • Object-oriented design involves ide...read more

Add your answer

Q54. Handle thread safety in singleton pattern

Ans.

Use synchronized block or double-checked locking to ensure only one thread can access singleton instance at a time.

  • Use synchronized block to ensure thread safety in getInstance() method

  • Implement double-checked locking to minimize synchronization overhead

  • Consider using Enum singleton for thread safety without synchronization

Add your answer

Q55. What is Singleton Design Pattern? Can we create a clone of an object from singleton class?

Ans.

Singleton Design Pattern ensures only one instance of a class exists. No, we cannot create a clone of an object from singleton class.

  • Singleton pattern restricts the instantiation of a class to one object.

  • It is used when only one object is required to coordinate actions across the system.

  • The instance is created only when it is requested for the first time.

  • The constructor of the singleton class is private.

  • Clone method is not supported in singleton pattern.

Add your answer

Q56. Explain any one design pattern with example

Ans.

Singleton design pattern ensures a class has only one instance and provides a global point of access to it.

  • Ensure a class has only one instance by providing a global access point to it

  • Lazy initialization to create the instance only when needed

  • Thread-safe implementation to handle multiple threads accessing the instance

  • Commonly used in logging, caching, database connections

Add your answer

Q57. Explain Entity FrameWork or any Design Pattern

Ans.

Entity Framework is an ORM tool that enables developers to work with databases using .NET objects.

  • Entity Framework is an Object-Relational Mapping (ORM) tool that allows developers to interact with databases using .NET objects.

  • It eliminates the need for writing SQL queries by translating LINQ queries into SQL queries.

  • It provides automatic generation of database schema based on the domain model.

  • Entity Framework supports various database providers such as SQL Server, MySQL, SQL...read more

Add your answer

Q58. how to design a 2 model in single window

Ans.

To design a 2 model in single window, use a split screen or tabbed interface.

  • Consider the user's workflow and prioritize the most important information

  • Use a clear visual hierarchy to differentiate between the two models

  • Provide easy navigation between the two models

  • Test the design with users to ensure usability and efficiency

Add your answer

Q59. What is Viewmodel?

Ans.

ViewModel is a class that is responsible for preparing and managing data for an activity or fragment.

  • ViewModel helps in separating the UI data from the UI controller logic.

  • It survives configuration changes such as screen rotations.

  • ViewModel is part of the Android Architecture Components.

  • Example: ViewModel can hold data retrieved from a database and provide it to the UI.

Add your answer

Q60. Have you created Custom Facade?

Ans.

Yes, I have created custom facades to provide a simplified interface to a complex subsystem.

  • Used to improve code readability and maintainability

  • Helps in decoupling the client code from the subsystem

  • Examples: Laravel's Facade pattern for database operations

Add your answer

Q61. Write code for that design pattern

Ans.

Factory Method Pattern

  • Defines an interface for creating objects, but lets subclasses decide which class to instantiate

  • Encapsulates object creation logic to a separate class

  • Useful when a class can't anticipate the type of objects it needs to create

  • Example: java.util.Calendar.getInstance()

  • Example: javax.xml.parsers.DocumentBuilderFactory.newInstance()

Add your answer
Frequently asked in

Q62. Design phone book application

Ans.

Phone book application to store and manage contacts

  • Allow users to add, edit, delete contacts

  • Implement search functionality to find contacts quickly

  • Include features like call, message, email directly from the app

Add your answer

Q63. Explain Saga design pattern

Ans.

Saga design pattern is used to manage long-lived transactions in distributed systems by breaking them into smaller, more manageable units.

  • Saga pattern involves breaking a long transaction into smaller, independent transactions called sagas.

  • Each saga consists of a series of steps that are executed in a specific order.

  • If a step fails, compensating transactions are executed to undo the changes made by the previous steps.

  • Saga pattern ensures that the system remains consistent eve...read more

Add your answer
Frequently asked in

Q64. DESIGN A MOD COUNTER

Ans.

A mod counter is a counter that counts from 0 to a specified modulus value before resetting to 0.

  • Design a counter with a specified number of bits to represent the count value

  • Implement logic to increment the count value by 1

  • Add logic to reset the count value to 0 when it reaches the modulus value

Add your answer
Frequently asked in

Q65. What is adapters and types of adaptables

Ans.

Adapters are used to convert the interface of a class into another interface that a client expects. Types of adaptables include object adapters and class adapters.

  • Adapters are used to make two incompatible interfaces work together.

  • Object adapters use composition to adapt the interface of a class.

  • Class adapters use multiple inheritance to adapt the interface of a class.

  • Adaptables can be objects or classes that need to be adapted.

  • Examples of adaptables include legacy systems, t...read more

Add your answer
Frequently asked in

Q66. Design Weather app ? What design pattern you will use to build this app ?

Ans.

Design a weather app using the Model-View-ViewModel (MVVM) design pattern.

  • Use MVVM design pattern to separate the presentation layer from the business logic and data access.

  • Model: Represents the data and business logic.

  • View: Represents the UI components.

  • ViewModel: Acts as a mediator between the Model and View, handling user interactions and updating the UI.

  • Use data binding to automatically synchronize the View with the ViewModel.

  • Implement a repository pattern to handle data r...read more

Add your answer

Q67. What are the usecases where CQRS pattern can be used ?

Ans.

CQRS pattern can be used in scenarios where read and write operations need to be separated for better scalability and performance.

  • CQRS can be used in applications with complex domain models that require different models for reading and writing data.

  • It can be beneficial in scenarios where read operations heavily outnumber write operations.

  • CQRS is useful when there is a need to optimize read and write operations independently.

  • Examples include e-commerce platforms for handling p...read more

Add your answer
Frequently asked in

Q68. Design a book reader service such as kindle

Ans.

Design a book reader service similar to Kindle

  • Implement a user-friendly interface for browsing and purchasing books

  • Include features like bookmarking, highlighting, and note-taking

  • Support various file formats such as PDF, EPUB, and MOBI

  • Provide options for customization like font size, background color, and reading progress tracking

Add your answer

Q69. Difference between factory and abstract factory design pattern

Ans.

Factory pattern creates objects without specifying the class type, while abstract factory pattern creates families of related objects without specifying their concrete classes.

  • Factory pattern creates objects through a common interface, without exposing the instantiation logic to the client.

  • Abstract factory pattern provides an interface to create families of related or dependent objects without specifying their concrete classes.

  • Factory pattern is a single method call to create...read more

Add your answer
Frequently asked in

Q70. what are the codes used in Design

Ans.

Various codes are used in design, such as color codes, HTML codes, CSS codes, and design software codes.

  • Color codes are used to specify colors in design, such as #FFFFFF for white.

  • HTML codes are used to structure web pages, like

    for heading 1.

  • CSS codes are used to style elements on a webpage, such as font-size: 16px;

  • Design software codes refer to commands and functions within design tools like Adobe Photoshop or Illustrator.

Add your answer

Q71. Share details of 2 design flows

Ans.

Two design flows are Agile and Waterfall.

  • Agile is an iterative approach that emphasizes flexibility and collaboration.

  • Waterfall is a linear approach that emphasizes planning and documentation.

  • Agile involves continuous feedback and adaptation.

  • Waterfall involves distinct phases of development.

  • Agile is suited for projects with changing requirements.

  • Waterfall is suited for projects with well-defined requirements.

Add your answer

Q72. What is adaptor?

Ans.

An adaptor is a device that allows different types of plugs or connectors to be used together.

  • Adaptors are commonly used in electronics to convert one type of plug to another, such as from a European plug to a US plug.

  • They can also be used in networking to connect different types of cables, such as Ethernet to USB.

  • Adaptors can be passive (simply changing the physical connection) or active (converting signals or voltages).

Add your answer
Frequently asked in

Q73. explain some design patterns like chain of responsibility.

Ans.

Chain of Responsibility is a behavioral design pattern that allows an object to pass a request along a chain of handlers.

  • Handlers are linked in a chain and each handler decides whether to process the request or pass it to the next handler

  • It decouples senders and receivers of requests

  • Commonly used in event handling systems and logging frameworks

Add your answer

Q74. What pattern have you followed while building modules.

Ans.

I have followed the modular design pattern while building modules.

  • I break down the software into smaller, independent modules that can be easily managed and maintained.

  • I ensure each module has a clear purpose and well-defined interfaces for communication with other modules.

  • I use techniques like encapsulation, abstraction, and separation of concerns to create modular designs.

  • Example: Using the MVC (Model-View-Controller) pattern to separate the presentation, business logic, an...read more

Add your answer

Q75. What is the SAGA pattern?

Ans.

The SAGA pattern is a design pattern used in distributed systems for managing long-lived transactions.

  • SAGA pattern breaks down a long transaction into a series of smaller, more manageable transactions.

  • Each smaller transaction is executed independently and can be compensated if needed.

  • SAGA pattern helps maintain consistency and reliability in distributed systems.

  • Example: In an e-commerce system, the SAGA pattern can be used to handle the process of placing an order, processing...read more

Add your answer
Frequently asked in

Q76. Design FSM - halway with 2 detectors, accuire amout of pepole in room - only one person can pass halway each time.

Ans.

Design a finite state machine to count the number of people passing through a hallway with 2 detectors, allowing only one person at a time.

  • Create states for each detector and the hallway

  • Transition between states based on detector inputs

  • Use counters to keep track of the number of people passing through

  • Implement logic to prevent multiple people from passing simultaneously

Add your answer

Q77. Explain Solid patterns

Ans.

Solid patterns are a set of five design principles to make software designs more understandable, flexible, and maintainable.

  • Single Responsibility Principle: A class should have only one reason to change.

  • Open/Closed Principle: Software entities should be open for extension but closed for modification.

  • Liskov Substitution Principle: Objects of a superclass should be replaceable with objects of its subclasses without affecting the functionality.

  • Interface Segregation Principle: A ...read more

Add your answer
Frequently asked in

Q78. How single design patterns work?

Ans.

Single design patterns work by providing a reusable solution to common problems in software development.

  • Design patterns help in organizing code and making it more maintainable.

  • They promote code reusability and flexibility.

  • Examples of single design patterns include Singleton, Factory, and Observer.

Add your answer

Q79. What is lightweight composite

Ans.

Lightweight composite is a material made by combining two or more different materials to create a stronger and lighter product.

  • Combination of materials like carbon fiber, fiberglass, and resin

  • Used in aerospace industry for aircraft components

  • Commonly used in sports equipment like tennis rackets and bicycles

Add your answer

Q80. What is gang of four design pattern.

Ans.

Gang of Four design patterns are a set of 23 software design patterns that were introduced in the book 'Design Patterns: Elements of Reusable Object-Oriented Software'.

  • Gang of Four design patterns were identified by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides.

  • These patterns are categorized into three groups: creational, structural, and behavioral.

  • Examples of Gang of Four design patterns include Singleton, Factory Method, Observer, and Strategy.

Add your answer
Frequently asked in

Q81. Explain adaptive design pattern

Ans.

Adaptive design pattern is a software design pattern that allows objects to change their behavior dynamically.

  • Adaptive design pattern involves creating objects that can change their behavior at runtime.

  • It allows for flexibility and adaptability in software systems.

  • Examples include Strategy pattern, State pattern, and Decorator pattern.

Add your answer
Frequently asked in

Q82. How to make singleton services multiton

Ans.

Singleton services can be made multiton by maintaining a map of instances with unique keys.

  • Create a map to store instances with unique keys

  • Use a factory method to retrieve instances based on keys

  • Ensure that only one instance is created per key

Add your answer
Frequently asked in

Q83. Explain Abstract design pattern.

Ans.

Abstract design pattern is a way to define a blueprint for a group of objects with common characteristics.

  • It allows creating objects without specifying their concrete classes.

  • It promotes loose coupling between classes.

  • It is implemented using abstract classes and interfaces.

  • Example: Shape is an abstract class and Circle, Square, Triangle are its concrete subclasses.

  • Example: JDBC API uses abstract classes and interfaces to provide a common interface for different database vendo...read more

Add your answer

Q84. What is saga design pattern

Ans.

Saga design pattern is used to manage long-lived transactions between microservices.

  • It ensures that all services involved in a transaction are either committed or rolled back together.

  • It uses a sequence of local transactions to achieve global consistency.

  • It can be implemented using either choreography or orchestration.

  • Example: A customer places an order, which involves multiple microservices such as inventory, payment, and shipping. Saga pattern ensures that if any of these s...read more

Add your answer

Q85. What is prototype pattern

Ans.

Prototype pattern is a creational design pattern that allows cloning of objects.

  • Used to create new objects by copying an existing object

  • Avoids the need for subclassing to create new objects

  • Can be implemented using shallow or deep copy methods

Add your answer
Frequently asked in

Q86. Explain one pattern you created

Ans.

I created a pattern called 'The Fibonacci Spiral' inspired by the Fibonacci sequence.

  • The Fibonacci Spiral is a geometric pattern that starts with a small square followed by a series of squares whose sides are the Fibonacci numbers.

  • Each square is connected to the next one in a spiral pattern, creating a visually appealing design.

  • The Fibonacci Spiral can be found in nature, art, and architecture due to its aesthetically pleasing proportions.

Add your answer

Q87. Explain the usage of that particular design pattern

Ans.

The design pattern is used to solve a specific problem in software development.

  • Design patterns are reusable solutions to common problems in software development.

  • They provide a standard way to solve a problem that can be adapted to different situations.

  • Examples of design patterns include Singleton, Factory, Observer, and Decorator.

  • Using design patterns can improve code quality, maintainability, and scalability.

Add your answer
Frequently asked in

Q88. Design a pub sub model

Ans.

A pub sub model allows for communication between multiple components by using a publish-subscribe pattern.

  • Components can publish messages to a topic

  • Subscribers can subscribe to specific topics to receive messages

  • Messages are not sent directly to subscribers, but rather through a central hub

Add your answer

Q89. Design chat box

Ans.

Design a chat box for seamless communication between users.

  • Include features like text messaging, emojis, file sharing, and notifications.

  • Design a user-friendly interface with easy navigation and customization options.

  • Implement real-time messaging functionality for instant communication.

  • Ensure data security and privacy by encrypting messages and providing secure login options.

Add your answer
Frequently asked in

Q90. Explain what is a API Gateway pattern

Ans.

API Gateway pattern is a design pattern used to route API requests to the appropriate microservices.

  • Centralized entry point for all API requests

  • Handles authentication, authorization, rate limiting, and logging

  • Helps in decoupling client applications from individual microservices

  • Can aggregate multiple requests into a single request for the client

  • Examples include Netflix Zuul, Amazon API Gateway

Add your answer

Q91. Design a logger class

Ans.

A logger class to handle logging messages in an application

  • Create a Logger class with methods like logInfo, logError, logWarning, etc.

  • Use a file or database to store the log messages

  • Include timestamp and severity level in each log message

  • Implement log rotation to manage log file size

Add your answer

Q92. What is Concurrency Design Pattern?

Ans.

Concurrency design pattern is a design pattern that deals with managing multiple tasks or processes simultaneously.

  • Concurrency design patterns help in improving performance and efficiency in multi-threaded applications.

  • Examples of concurrency design patterns include Producer-Consumer, Reader-Writer, and Thread Pool.

  • These patterns help in avoiding issues like race conditions, deadlocks, and resource contention.

Add your answer

Q93. What is generic patterens

Ans.

Generic patterns refer to common design structures or solutions that can be applied across different contexts or scenarios.

  • Generic patterns help in creating reusable and scalable solutions.

  • They provide a framework for solving similar problems in various situations.

  • Examples include design patterns like Singleton, Factory, and Observer.

  • Generic patterns can be applied in software development, architecture, and even project management.

Add your answer
Frequently asked in

Q94. Explain repository design pattern

Ans.

Repository design pattern is a structural design pattern that separates the data access logic from the business logic in an application.

  • It provides a way to access data from a data source without exposing the underlying data access code to the business logic.

  • It helps in achieving separation of concerns by keeping data access code in a separate layer.

  • Commonly used in applications where data needs to be accessed from multiple sources like databases, APIs, or files.

Add your answer
Frequently asked in

Q95. What is composite structure

Ans.

Composite structure is a material made from two or more different materials with different physical or chemical properties.

  • Composite structures are designed to combine the strengths of each material used.

  • Examples include carbon fiber reinforced polymer (CFRP) and fiberglass reinforced plastic (FRP).

  • They are commonly used in aerospace, automotive, and construction industries.

Add your answer

Q96. What is Bloc pattern explain in details

Ans.

Bloc pattern is a design pattern for managing state in Flutter applications.

  • Bloc stands for Business Logic Component

  • Helps separate presentation layer from business logic

  • Uses streams to handle state changes

  • Popular package for implementing Bloc pattern is 'flutter_bloc'

Add your answer

Q97. Design patterns used in android

Ans.

Design patterns in Android are reusable solutions to common problems in software design.

  • MVC (Model-View-Controller) - separates the application into three main components: the model, the view, and the controller.

  • MVVM (Model-View-ViewModel) - separates the user interface into three main components: the model, the view, and the view model.

  • Singleton - ensures that a class has only one instance and provides a global point of access to it.

  • Observer - defines a one-to-many dependenc...read more

Add your answer

Q98. Design patterns of php

Ans.

PHP has several design patterns such as Singleton, Factory, Observer, and MVC.

  • Singleton pattern ensures only one instance of a class is created.

  • Factory pattern creates objects without exposing the instantiation logic.

  • Observer pattern allows objects to be notified of changes to a subject.

  • MVC pattern separates the application into Model, View, and Controller components.

Add your answer

Q99. Design pattern in python

Ans.

Design patterns in Python are reusable solutions to common problems in software design.

  • Design patterns help in creating maintainable and scalable code.

  • Some common design patterns in Python include Singleton, Factory, Observer, and Strategy.

  • Each design pattern has its own purpose and implementation.

  • Design patterns promote code reusability and flexibility.

Add your answer

Q100. oops concepts in technology, design patterns

Ans.

Object-oriented programming concepts and reusable solutions for common problems.

  • Encapsulation, inheritance, and polymorphism are key OOP concepts.

  • Design patterns provide reusable solutions for common programming problems.

  • Examples of design patterns include Singleton, Factory, and Observer.

  • Understanding OOP and design patterns can lead to more efficient and maintainable code.

Add your answer
Frequently asked in
1
2
3
Interview Tips & Stories
Ace your next interview with expert advice and inspiring stories

Interview experiences of popular companies

3.7
 • 10k Interviews
3.9
 • 7.8k Interviews
3.7
 • 7.3k Interviews
3.8
 • 5.4k Interviews
3.7
 • 5.2k Interviews
3.8
 • 4.6k Interviews
3.6
 • 3.6k Interviews
3.5
 • 2.3k Interviews
3.7
 • 860 Interviews
View all
Design Patterns Interview Questions
Share an Interview
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
70 Lakh+

Reviews

5 Lakh+

Interviews

4 Crore+

Salaries

1 Cr+

Users/Month

Contribute to help millions
Get AmbitionBox app

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter