GoConqr has a new look! Let us know what you think.

Flashcards

Design patterns

Turið Højgaard BDSA 3rd semester English 50 cards

Design patterns

Cards in this deck (50)

  1. 1What is a design pattern?Design patterns are ways to describe best practices, good designs, and capture experience in a way that it is possible for others to reuse this experience.
    It also creates a way for software developers to describe and discuss their code.
    Unlike a library or framework, which can be inserted and used right away, a design pattern is more of a template to approach the problem at hand.
  2. 2How are design patterns discovered?Software engineering community encounters a problem often and comes up with a generalized solution.
  3. 3When are design patterns used?When it can be applied to solving a given problem and the pros of using it outweighs the cons.
  4. 4What types of design patterns are there and what are their characteristics?- Behavioural: Are concerned with algorithms and the assignment of responsibilities between objects.
    - Structural: Used for structuring objects and classes.
    - Creational: Used for object creation.
  5. 5What design patterns are categorized as Behavioural patterns?Template Method
    Strategy
    Mediator
    Observer
    Visitor
  6. 6What design patterns are categorized as Structural patterns?Adapter
    Bridge
    Composite
    Façade
    Proxy
    Gateway
  7. 7What design patterns are categorized as Creational patterns?Factory
    Singleton
  8. 8Advantages of Design Patterns?Patterns don't provide solutions, they inspire solutions. Patterns explicitly capture expert knowledge and design tradeoffs and make this expertise widely available. They ease the transition to object-oriented technology
  9. 9Disadvantages of Design Patterns?Using design patterns requires extensive knowledge.
    Having design patterns available can also lead to people believing that apparently all problems can be solved using existing design patterns. In short, this can limit creativity and the desire to find new (better) solutions.
  10. 10Design pattern: Template Method - what is the intent?It defines the skeleton of an algorithm in a method, deferring some steps to subclasses. It allows subclasses to override certain steps of an algorithm without changing the overall structure of the algorithm.
    It helps maintain the Dependency Inversion Principle.
  11. 11Show an example of how the Template Method pattern could be implemented (UML)Show an example of how the Template Method pattern could be implemented (UML)
  12. 12How to spot when Template Method pattern is usedWhen you have a lot of similar classes that only differ in the way they execute some behaviour.
    or
    A method in base class that calls a bunch of other methods that are either abstract or empty
  13. 13Design pattern: Strategy - what is the intent?It defines the skeleton of an algorithm in a method, deferring some steps to subclasses. It allows subclasses to override certain steps of an algorithm without changing the overall structure of the algorithm.
    It helps maintain the Dependency Inversion Principle.
    Extra benefit: Allows defining multiple strategies to resolve a problem
  14. 14Show an example of how the Strategy pattern could be implemented (UML)Show an example of how the Strategy pattern could be implemented (UML)
  15. 15How to spot when Strategy pattern is usedWhen you have a lot of similar classes that only differ in the way they execute some behaviour
  16. 16Template Method pattern vs Strategy pattern:TEMPLATE METHOD is simple to write and simple to use but is also inflexible.
    STRATEGY is flexible, but you have to create an extra class, instantiate an extra object, and wire the extra object into the system.
    So the choice between TEMPLATE METHOD and STRATEGY depends on whether you need the flexibility of STRATEGY (having different strategies) or can live with the simplicity of TEMPLATE METHOD.
  17. 17Design pattern: Façade - what is the intent?It provides a simplified interface to a complex system. It hides the complexity of the system and exposes a unified interface to the client - like an API.
  18. 18Show an example of how the Façade pattern could be implemented (UML)Show an example of how the Façade pattern could be implemented (UML)
  19. 19How to spot when Façade pattern is usedFacade can be recognized as a class that has a simple interface, but delegates most of the work to other classes.
  20. 20Design pattern: Mediator - what is the intent?It allows multiple objects to communicate with each other through a mediator object, instead of directly communicating with each other.
    The mediator object controls the communication between the objects and reduces the dependencies between them - like a controller in MVC.
  21. 21Show an example of how the Mediator pattern could be implemented (UML)Show an example of how the Mediator pattern could be implemented (UML)
  22. 22How to spot when Mediator pattern is usedMany classes depend on one classHow to spot when Mediator pattern is used
  23. 23Façade pattern vs. Mediator pattern:Both imposes some policy on the members.
    Façade, the policies are visible to the users.
    Mediator is hidden for the users.
    (they are the opposite)
  24. 24Design pattern: Singleton - what is the intent?It is useful when you need to ensure that a class has only one instance, and that the instance is easily accessible from anywhere in the code (a global access point)
  25. 25Show an example of how the Singleton pattern could be implemented (UML)Show an example of how the Singleton pattern could be implemented (UML)
  26. 26How to spot when Singleton pattern is usedPrivate constructor.
    A static creation/getInstance method, which returns the same object.
  27. 27Design pattern: Factory - what is the intent?It provides an interface for creating objects in a super class, but allows subclasses to alter the type of objects that will be created.
    It maintains the Dependency Inversion Principle.
  28. 28Show an example of how the Factory pattern could be implemented (UML)Show an example of how the Factory pattern could be implemented (UML)
  29. 29How to spot when Factory pattern is usedA class named factory/creator or methods like MakeSomething() or CreateSomething()
  30. 30Design pattern: Composite - what is the intent?It allows you to compose objects into tree structures and treat individual objects and compositions of objects uniformly.
  31. 31Show an example of how the Composite pattern could be implemented (UML)Show an example of how the Composite pattern could be implemented (UML)
  32. 32How to spot when Composite pattern is usedA class called Composite/Compound inherits an interface. Has an add method and maybe a remove method.
    Other “simple” classes inheriting the same interface
  33. 33Design pattern: Observer - what is the intent?It allows an object to subscribe to receive notifications from another object when its state changes.
    Defines a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.
  34. 34Show an example of how the Observer pattern could be implemented (UML)Show an example of how the Observer pattern could be implemented (UML)
  35. 35How to spot when Observer pattern is usedClasses called Observer/State/Subject.
    A class that has a notify() method or an array of other objects (observers)
  36. 36Design pattern: Adapter - what is the intent?Allows objects with incompatible interfaces to collaborate
  37. 37Show an example of how the Adapter pattern could be implemented (UML)This is called an Object adapter. It can also be implemented as a Class adapter, but only in languages that allow multiple inheritance (C++, not C#)Show an example of how the Adapter pattern could be implemented (UML)
  38. 38How to spot when Adapter pattern is usedAdapter class inheriting from both some existing code and a 3rd party app/library.
    Adapter class inheriting from two incompatible interfaces/classes
  39. 39Design pattern: Bridge - what is the intent?Lets you split a large class or a set of closely related classes into two separate hierarchies—abstraction and implementation—which can be developed independently of each other.
    Abstraction = GUI and implementation = Code
    As a result, you can change the GUI classes without touching the logic-related classes
  40. 40Show an example of how the Bridge pattern could be implemented (UML)Show an example of how the Bridge pattern could be implemented (UML)
  41. 41How to spot when Bridge pattern is usedTwo connected inheritance hierarchies. One concerned with abstraction (GUI) and one with implementation
  42. 42Design pattern: Proxy - what is the intent?It provides an object that acts as a substitute for a real service object used by a client. A proxy receives client requests, does some work (access control, caching, etc.) and then passes the request to a service object.Design pattern: Proxy - what is the intent?
  43. 43Show an example of how the Proxy pattern could be implemented (UML)Show an example of how the Proxy pattern could be implemented (UML)
  44. 44How to spot when Proxy pattern is usedA Proxy class that delegates all the work to other service objects
  45. 45Design pattern: Gateway - what is the intent?It allows you to provide a simplified interface to a complex subsystem.
    It creates a separation between business logic and database.
    It provides a single point of access for a system or subsystem and therefore hides the details of fetching entities and queries over entities.
  46. 46Show an example of how the Gateway pattern could be implemented (UML)Show an example of how the Gateway pattern could be implemented (UML)
  47. 47How to spot when Gateway pattern is usedGateways connected to a database
  48. 48Design pattern: Visitor - what is the intent?It allows you to define a new operation without changing the classes of the elements on which it operates.
    - This helps us maintain the Open/Closed Principle.
    Lets you isolate particular behaviors/algorithms from the objects on which they operate, and places them in a single class.
    - Solves the Single Responsibility Principle.
  49. 49Show an example of how the Visitor pattern could be implemented (UML)Show an example of how the Visitor pattern could be implemented (UML)
  50. 50How to spot when Visitor pattern is usedHas a Visitor interface and/or a concrete visitor class.
    A concrete class or interface has similar methods for each element class.
    Has accept methods and visit methods

Information

Description
3rd semester BDSA Flashcards on Design patterns, created by Turið Højgaard on 27/12/2022.
Views
3
Rating

Feedback

What is it about?

What do you think of the new look?

How do you like it?