Design Patterns an der LMU München

Arrow Arrow

Komplett kostenfrei

studysmarter schule studium
d

4.5 /5

studysmarter schule studium
d

4.8 /5

studysmarter schule studium
d

4.5 /5

studysmarter schule studium
d

4.8 /5

Lerne jetzt mit Karteikarten und Zusammenfassungen für den Kurs Design Patterns an der LMU München.

Beispielhafte Karteikarten für Design Patterns an der LMU München auf StudySmarter:

What is the Decorator Pattern?

Beispielhafte Karteikarten für Design Patterns an der LMU München auf StudySmarter:

What is the Strategy Pattern?

Beispielhafte Karteikarten für Design Patterns an der LMU München auf StudySmarter:

What is the Observer Pattern?

Beispielhafte Karteikarten für Design Patterns an der LMU München auf StudySmarter:

What is the Factory Method Pattern?

Beispielhafte Karteikarten für Design Patterns an der LMU München auf StudySmarter:

What is the Adapter Pattern?

Beispielhafte Karteikarten für Design Patterns an der LMU München auf StudySmarter:

What is the Command Pattern?

Beispielhafte Karteikarten für Design Patterns an der LMU München auf StudySmarter:

What is the Singleton Pattern?

Beispielhafte Karteikarten für Design Patterns an der LMU München auf StudySmarter:

What is the Null Object Pattern?

Beispielhafte Karteikarten für Design Patterns an der LMU München auf StudySmarter:

What is the Template Method Pattern?

Beispielhafte Karteikarten für Design Patterns an der LMU München auf StudySmarter:

1. What are the structural patterns?

2. What are the differences between the structural patterns?

Beispielhafte Karteikarten für Design Patterns an der LMU München auf StudySmarter:

What is the Composite Pattern?

Beispielhafte Karteikarten für Design Patterns an der LMU München auf StudySmarter:

What is the Facade Pattern?

Kommilitonen im Kurs Design Patterns an der LMU München. erstellen und teilen Zusammenfassungen, Karteikarten, Lernpläne und andere Lernmaterialien mit der intelligenten StudySmarter Lernapp. Jetzt mitmachen!

Jetzt mitmachen!

Flashcard Flashcard

Beispielhafte Karteikarten für Design Patterns an der LMU München auf StudySmarter:

Design Patterns

What is the Decorator Pattern?

– structural design pattern

– change behaviour of an object dynamically/ at run time, so object code is not changed

– object (inner) is wrapped in another object (outer) called a decorator

– decorator is a & has a inner object, they have the same type and can be used interchangeably

– decorators can wrap other decorators

– flexible alternative to sub classes where you have too many of them

– use composition to share behaviour, not inheritance

Example:

– vegan Karamell Macchiato is wrapped by Caramel which is wrapped by Soy

(S (C (M) ) )

Beverage: abstract class

Macchiato: concrete class (type Beverage)

Add-on: abstract class

Soy: concrete class (type Add-on)

Caramel: concrete class (type Add-on)

Note: not a good example, bc only e.g. cost method different and Add-on is not a Beverage -> use decorator when behaviour is different not properties & Decorator is an object

Design Patterns

What is the Strategy Pattern?

– behavioural pattern

– use composition (has-a) instead of inheritance (is-a)

– behaviour can be easily shared top to down, but not on the same level in the class hierarchy. What to do if 2 sub classes have the same fly method, but one shares eat method with other subclass? 

=> bad structure, solution to problems with inheritance is not more inheritance

– split clients and algorithms/methods -> create strategies/interfaces for flying, eating like IFlyStrategy & IEatStrategy

SimpleFlyStrategy and SimplyNoFlyStrategy implement IFlyStrategy

Duck has IFlyStrategy & IEatStrategy.

Design Patterns

What is the Observer Pattern?

– behavioural design pattern

– use: one component (observer) subscribes/registers to another component (observable) which notifies the observer when it changes its state

– one-to-many relationship: when one object changes it notifies all its dependencies so that they react to the change

– Example: weather station with sensors notifies displays to update when temperature changes

– Interfaces IObservable has 0…* IObservers

– ConcreteObservable can register, unregister ConcreteObservers & notify them, getState() & setState()

– ConcreteObservers update

Design Patterns

What is the Factory Method Pattern?

– defines an interface for creating an object, but lets subclasses decide which object to instantiate (defer decision to subclasses)

– use when you don’t know which object you want to create yet (else you would just pass in which object with dependency injection) -> factory holds business logic responsible for object creation

+ construction might be complex

+ composition instead of inheritance -> only few main classes which create objects with properties

Example:

RandomAnimalFactory (createAnimal() randomly), BalancedAnimalFactory (createAnimal() depending on existing animals)

Design Patterns

What is the Adapter Pattern?

– analogy: adapter for sockets in different countries

– Client has a ITarget with method request()

– Adapter implements ITarget & method request()

– Adapter has a Adaptee class to which it delegates the request

Design Patterns

What is the Command Pattern?

– receiver & sender object

– request/command to sender object is encapsulated

– objects can be parameterised by command or even a queue of commands

– undo on command is possible

e.g. Smart Home (lights):

– Turn on light of all lamps command is attached to turn on button, send/execute command whenever button is pressed

remote control (invoker) executes command to change light (receiver)

Architecture:

– Invoker has 0..* ICommand, which is implemented by Concrete Command (like turn off all light in bathroom) which has a receiver

Invoker method: setCommand(ICommand)

ICommand: execute, unexecute

Design Patterns

What is the Singleton Pattern?

– ensures that a class has only one instance and provides public access to that instance

– controversial pattern/people think it is a code smell

– private constructor, static method which checks if instance exists, if yes return, if no creates a Singleton instance and returns it

Negative:

– global instance -> instance might change without knowing because anybody can access global space to change the instance

– you have to know that you only want one instance in the future

– difficult to Unit test since the global instance has to be mocked

Design Patterns

What is the Null Object Pattern?

– Example 1: MovingBehaviour (Up, Down, Left, Right, NoMovingBehaviour = Null Object)

– Example 2: Tree Structure (Composite Pattern: Composites & Leaves), Components implement Iterator pattern, Composites return CompositeIterator,  but when calling getIterator() on Leaves, NullIterator object is returned (hasNext() is false, isDone() is false)

=> by that if else / switch statements can be avoided

Design Patterns

What is the Template Method Pattern?

– take the template and fill in the gaps with the template

– SpecialPoster (e.g. Hero poster) extends PosterTemplate

– defines a skeleton of an algorithm, deferring some steps to sub classes

– structure of algorithm remains invariant

Design Patterns

1. What are the structural patterns?

2. What are the differences between the structural patterns?

1. Decorator, Adapter, Facade, Proxy, Bridge

2.

Adapter vs. Proxy: 

Adapter 2 different interfaces, no behavior change

Proxy 2 similar interfaces, behavior change, namely access control

Adapter vs. Facade:

– Facade already has behavior, but you want to simplify it, more logic involved than in adapter

Adapter vs Proxy:

– adapter changes the interface but not the implementation

– proxy changes the implementation but not the interface

Bridge vs Decorator:

– Decorator all interfaces are the same, 1 hierarchy

– Bridge interfaces are not the same, 2 hierarchies

Design Patterns

What is the Composite Pattern?

– composes objects into a tree structure to represent part-whole hierarchies

– lets clients treat individual objects (leaves in a tree) and compositions of objects (the branches & nodes which are not leaves) uniformly

Design Patterns

What is the Facade Pattern?

– Metaphor: Facade of building (a building is more than the facade namely e.g. the wiring)

– you only interact with the face of the building

– class Facade invokes methods of other classes which don’t have a clear structure (it can be just a mess)

– Facade doesn’t add new functionality, it is just a high-level interface which hides the complexity of some low-level sub-systems

– a client then can use only the Facade instead of interacting with all the complex relationships between the interacting classes

– Example: third-party library

Melde dich jetzt kostenfrei an um alle Karteikarten und Zusammenfassungen für Design Patterns an der LMU München zu sehen

Singup Image Singup Image
Wave

Andere Kurse aus deinem Studiengang

Für deinen Studiengang an der LMU München gibt es bereits viele Kurse auf StudySmarter, denen du beitreten kannst. Karteikarten, Zusammenfassungen und vieles mehr warten auf dich.

Zurück zur LMU München Übersichtsseite

Was ist StudySmarter?

Was ist StudySmarter?

StudySmarter ist eine intelligente Lernapp für Studenten. Mit StudySmarter kannst du dir effizient und spielerisch Karteikarten, Zusammenfassungen, Mind-Maps, Lernpläne und mehr erstellen. Erstelle deine eigenen Karteikarten z.B. für Design Patterns an der LMU München oder greife auf tausende Lernmaterialien deiner Kommilitonen zu. Egal, ob an deiner Uni oder an anderen Universitäten. Hunderttausende Studierende bereiten sich mit StudySmarter effizient auf ihre Klausuren vor. Erhältlich auf Web, Android & iOS. Komplett kostenfrei. Keine Haken.

Awards

Bestes EdTech Startup in Deutschland

Awards
Awards

European Youth Award in Smart Learning

Awards
Awards

Bestes EdTech Startup in Europa

Awards
Awards

Bestes EdTech Startup in Deutschland

Awards
Awards

European Youth Award in Smart Learning

Awards
Awards

Bestes EdTech Startup in Europa

Awards

So funktioniert's

Top-Image

Individueller Lernplan

StudySmarter erstellt dir einen individuellen Lernplan, abgestimmt auf deinen Lerntyp.

Top-Image

Erstelle Karteikarten

Erstelle dir Karteikarten mit Hilfe der Screenshot-, und Markierfunktion, direkt aus deinen Inhalten.

Top-Image

Erstelle Zusammenfassungen

Markiere die wichtigsten Passagen in deinen Dokumenten und bekomme deine Zusammenfassung.

Top-Image

Lerne alleine oder im Team

StudySmarter findet deine Lerngruppe automatisch. Teile deine Lerninhalte mit Freunden und erhalte Antworten auf deine Fragen.

Top-Image

Statistiken und Feedback

Behalte immer den Überblick über deinen Lernfortschritt. StudySmarter führt dich zur Traumnote.

1

Lernplan

2

Karteikarten

3

Zusammenfassungen

4

Teamwork

5

Feedback