Loading, please wait ...

Short Questions for Design Patterns

  • ×

    Hidden Questions!

    Some short questions are not visible. Usually teachers hides their visibility if they are few in number. Subject Expert recommends them to have more than 70+ questions against the topic and make them public.

  • 1 Discuss the advantages/disadvantages of Inheritance

    Answer
    Advantages:

    • New implementation is easy
    • Easy to modify or extend the existing implementation
    Disadvantages:
    • Breaks encapsulation
    • White box reuse
    • Subclasses may have to be changed if the implementation of super class changes
    • Implementation inheritance from super classes cannot be changed at run time.


  • 2 Discuss design patterns categories with at least two examples in each category?

    Answer

    1. Creational patterns concern the process of object creation. Your program gains more flexibility in deciding which objects need to be created for a given case. Provide a solution, as they "abstract the instantiation process. They help make a system independent of how its objects are created, composed, and represented“. Examples:
      • Abstract Factory
      • Building
      • Factory Method
      • Prototype
      • Singleton
    1. Structural patterns deal with the composition of classes or objects. This category utilizes "inheritance to distribute behavior between classes". They help you compose groups of objects into larger structures, to perform a complex function. Examples:
      • Adapter
      • Bridge
      • Composite
      • Decorator
      • Facade
      • Flyweight
      • Proxy
    2. Behavioral patterns characterize the ways in which classes or objects interact and distribute responsibility. They help you define the communication between objects in your system as well as the flow of control in a complex program. Examples:
      • Chain of Responsibility
      • Command
      • Interpreter
      • Iterator
      • Mediator
      • Memento
      • Observer
      • State
      • Strategy
      • Template Method
      • Visitor


  • 3 Briefly describe these designing problems of object oriented systems: "Tight coupling", "Extending functionality by subclassing" and "Inability to alter classes conveniently".

    Answer

    1. Tight coupling. Classes that are tightly coupled are hard to reuse in isolation, since they depend on each other. Tight coupling leads to monolithic systems, where you can't change or remove a class without understanding and changing many other classes. Loose coupling increases the probability that a class can be reused by itself and that a system can be learned, ported, modified, and extended more easily.
      • Design patterns: Abstract Factory, Bridge, Chain of Responsibility, Command, Facade, Mediator, Observer.
    2. Extending functionality by subclassing. Subclassing has its disadvantages. We should favor composition, but heavy use of object composition can make designs harder to understand. Many design patterns produce designs in which you can introduce customized functionality just by defining one subclass and composing its instances with existing ones.
      • Design patterns: Bridge, Chain of Responsibility, Composite, Decorator, Observer, Strategy.
    3. Inability to alter classes conveniently. Sometimes you have to modify a class that can't be modified conveniently. Perhaps you need the source code and don't have it (as may be the case with a commercial class library). Or maybe any change would require modifying lots of existing subclasses. Design patterns offer ways to modify classes in such circumstances.
      • Design patterns: Adapter, Decorator, Visitor.


  • 4 Describe common known designing problems and suggest respective designing patterns.

    Answer

    1. Creating an object by specifying a class explicitly. Specifying a class name when you create an object commits you to a particular implementation instead of a particular interface. This commitment can complicate future changes.
      • Design patterns: Abstract Factory , Factory Method , Prototype.
    2. Dependence on specific operations. When you specify a particular operation, you commit to one way of satisfying a request. By avoiding hard-coded requests, you make it easier to change the way a request gets satisfied both at compile-time and at run-time.
      • Design patterns: Chain of Responsibility, Command
    3. Dependence on hardware and software platform. External operating system interfaces and application programming interfaces (APIs) are different on different hardware and software platforms. Software that depends on a particular platform will be harder to port to other platforms. It may even be difficult to keep it up to date on its native platform. It's important therefore to design your system to limit its platform dependencies.
      • Design patterns: Abstract Factory, Bridge.
    4. Dependence on object representations or implementations. Clients that know how an object is represented, stored, located, or implemented might need to be changed when the object changes. Hiding this information from clients keeps changes from cascading.
      • Design patterns: Abstract Factory, Bridge, Memento, Proxy.
    5. Algorithmic dependencies. Algorithms are often extended, optimized, and replaced during development and reuse. Objects that depend on an algorithm will have to change when the algorithm changes. Therefore algorithms that are likely to change should be isolated.
      • Design patterns: Builder, Iterator, Strategy, Template Method, Visitor


  • 5 How are observe pattern participants?

    Answer

    There are four participants:

    1. Subject
    2. Observer
    3. Concrete Subject
    4. Concrete observer


  • 6 Define Aggregation?

    Answer
    There are some following points:

    • Class A contains Class B , Or Class A has instance of Class B.
    • Used when life of object is independent of container object But still container object owns the aggregated object.
    • Represented by the line with diamond.
    • Life /existence of the aggregated objects are independent of each other, But one object is playing the role of Owner of the other object.


  • 7 Define Association?

    Answer

    • In association Class A uses Class B.
    • Used when one object wants another object to perform a service for it.
    • Represented by just the line (no diamond)
    • Life / existence of the associated objects are independent of each other, They just provide some kind of service to each other


  • 8 Who is good designer?

    Answer

    Good designers do not solve every problem from scratch.They reuse solutions.

    • This is different from code reuse.
    • We need a way to record experience in software design such that others can reuse these experiences


  • 9 What are the benefits of design patterns?

    Answer

    1. Enable reuse of software design
    2. Explicitly capture expert knowledge and design trade offs
    3. Help improve developer communication
    4. Enhance the understanding of the design/implementation
    5. Add flexibility and modularity to the code
    6. Facilitate restructuring (re-factoring) the software


  • 10 List some common known designing problems?

    Answer

    • Creating an object by specifying a class explicitly
    • Dependency on a specific operation
    • Creating an object by specifying a class explicitly
    • Dependence on hardware and software platform
    • Dependence on object representations or implementations
    • Algorithmic dependencies
    • Tight coupling
    • Extending functionality by subclassing
    • Inability to alter classes conveniently


  • 11 Briefly describe Open/Closed principle?

    Answer
    This principles enforces developers to develop software in such a way that the code remains open for extension But closed for modification. If we allow adding new modules and classes this will add scalability to our product, But if we allow modification in existing code then we may broke the existing functionality.


  • 12 How a dependency on a specific operation is a designing problem?

    Answer
    When you specify a particular operation, you commit to one way of satisfying a request. By avoiding hard-coded requests, you make it easier to change the way a request gets satisfied both at compile-time and at run-time.


  • 13 Creating an object by specifying a class explicitly is a designing problem. Justify your answer with Yes Or No?

    Answer
    Yes, Its a designing problem. Specifying a class name when you create an object commits you to a particular implementation instead of a particular interface. This commitment can complicate future changes in the class.


  • 14 The GoF's (Gange of Four scientist) design patterns rely on which OO Design Principles?

    Answer
    They rely on two major OO design principles which are below:

    1. Favor Composition over Inheritance
    2. Program to an interface, not to an implementation.


  • 15 What are design patterns?

    Answer

    • A design pattern systematically names, explains and evaluates an important and recurring design problem and its solution.
    • They names and makes explicit a higher-level structure which is not directly supported by a programming language
    • Its a way to reuse solutions for common known problems instead of solving them from scratch.
    • They are not like code reuse and record experiences in software design.


Contact Us

support@subexpert.com
Write to Us View Help
Subject Expert Logo

Subject Expert

Learn, Evaluate and Optimize

Follow Us
Facebook Switch Display Mode Enable Translation
© 2024 - Subject Expert