Design Patterns

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

pure fabrication

- Assign a highly cohesive set of responsibilities to an artificial or convenience class that does not represent a problem domain concept ― something made up, to support high cohesion, low coupling, and reuse.

pattern drawbacks

- Patterns do not lead to direct code reuse. - Individual patterns are deceptively simple. - Composition of different patterns can be very complex. - Designers may suffer from pattern overload. - Patterns are validated by experience and discussion rather than by automated testing. - Integrating patterns into a software development process is a human-intensive activity.

Responsibility Driven Development

- emphasizes modelling of objects' roles, responsibilities, and collaborations. in RDD we think that objects have responsibility abstraction of what they do. doing the responsibility knowing the responsibility it is a metaphor for think about oo design. Think of software object as similar to people with responsibility who collaborate with other people to get work done.

protected variation

- identify point of predicted variation or instability. Assign responsibilities to create a stable interface around them. - isolate things which are likely to cause future changes - information hiding - open-closed principle

Criticism of design patterns

- target the wrong problem - Lacks formal foundations - Leads to inefficient solutions - Does not differ significantly from other abstractions

Anti-patterns

An AntiPattern is a pattern that tells how to go from a problem to a bad solution

Decorator

Attaches additional responsibilities to an object dynamically. decorators provide a flexible alternative to subclassing for extending functionality

Strategy

Defines a family of algorithms, encapsulates each one, and makes them interchangeable. it lets the algorithm vary independently from clients that use it.

Structural patterns

In Software Engineering, Structural Design Patterns are Design Patterns that ease the design by identifying a simple way to realize relationships between entities. -Adapter Match interfaces of different classes -Bridge Separates an object's interface from its implementation -Composite A tree structure of simple and composite objects -Decorator Add responsibilities to objects dynamically -Facade A single class that represents an entire subsystem -Flyweight A fine-grained instance used for efficient sharing -Private Class Data Restricts accessor/mutator access -Proxy An object representing another object

Behavioral patterns

In software engineering, behavioral design patterns are design patterns that identify common communication patterns between objects and realize these patterns. By doing so, these patterns increase flexibility in carrying out this communication. -Chain of responsibility A way of passing a request between a chain of objects -Command Encapsulate a command request as an object -Interpreter A way to include language elements in a program -Iterator Sequentially access the elements of a collection -Mediator Defines simplified communication between classes -Memento Capture and restore an object's internal state -Null Object Designed to act as a default value of an object -Observer A way of notifying change to a number of classes -State Alter an object's behavior when its state changes -Strategy Encapsulates an algorithm inside a class -Template method Defer the exact steps of an algorithm to a subclass -Visitor Defines a new operation to a class without change

Compound: MVC

Model: implement the observer pattern to keep interesting objects updated when state change occur. Using the observer pattern keeps the model completely independent of the views and controllers. it allows us to use different views with the same model, or even use multiple views at once View: the display consists of nested set of windows, panels, buttons, text labels and so on. Each display component is a composite (like a window) or a leaf (like a button). When the controller tells the view to update, it only has to tell top view component, and Composite takes care of the rest View and controller: implement the classic strategy pattern: the view is an object that configured with a strategy. the controller provides the strategy. The view is concerned only with the visual aspects of the application, and delegates to the controller for any decisions about the interface behaviour. using the strategy pattern also keep the view decoupled from model because it is the controller that is responsible for interacting with the model to carry out user requests. The view know nothing about how this gets done.

Creational design patterns

These design patterns are all about class instantiation. This pattern can be further divided into class-creation patterns and object-creational patterns. While class-creation patterns use inheritance effectively in the instantiation process, object-creation patterns use delegation effectively to get the job done. -Abstract Factory Creates an instance of several families of classes -Builder Separates object construction from its representation -Factory Method Creates an instance of several derived classes -Object Pool Avoid expensive acquisition and release of resources by recycling objects that are no longer in use -Prototype A fully initialized instance to be copied or cloned -Singleton A class of which only a single instance can exist

Pipes-and-Filters

This is useful when application involves processing something through a series transformations, and the ordering of the transformations is changeable.

Expert

assign a responsibility to the information expert - the class that has information necessary to fulfill the responsibility

Peer-to-Peer

client and server is also client and server

Multiple client/multiple service

clients communicate with multiple services, usually sequentially but could also be parallel, each service respond to client requests. each service handles multiple clients request. a service may delegate a client request to different service Ex. Distributed process

high cohesion

cohesion is a measure of how strongly related and focused the responsibility of an element are ( high cohesion mean it should have 1 job and 1 job only), assign a responsibility so that cohesion remain high

Layers of abstraction

components at lower layers provide services for component at higher layers. Components may use only services provided by components at lower layers ex: OS, Communication protocol, SPL

Adapter

converts the interface of a class into another interface the client expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces

Factory

define an interface for creating an object, but lets subclasses decide which class to instantiate. Factory method lets a class defer instantiation to subclasses

Observer

define one-to-many relationship among objects so that when one object changes state, all of its dependents are notified and updated automatically.

Low coupling

is a measure of how strongly one element is connected to, has knowledge of, or relies on other elements. An element with low (or weak) coupling is not dependent on too many other elements solution: assign a responsibility so that coupling remains low

Controller

is the first object beyond the UI layer that is responsible for receiving or handling a system operation message. solution: assign the responsibility to a class representing one of the following choices - represents the overal "system" as root object, a device that the software is running within - represent a use case scenario within which the system event occurs

Composite

is used where we need to treat a group of objects in similar way as a single object. it composes objects in term of a tree structure to represent part as well as whole hierarchy. it creates a tree structure of group of objects

Creator

it is a principle for the assignment of creation responsibilities. Assigned well, the design can support low coupling, increased clarity, encapsulation, and reusability ex: class B contains, compositely aggregate, record, closely use A

Broker

services register with broker, Consumer send service request to broker, Broker acts as intermediary between consumer and provider

Singleton

the pattern ensures a class has only one instance, and provides a global point of access to it

polymorphism

when related alternatives or behaviour vary by the type (class), assign responsibility for the behaviour to the types for which the behaviour varies


Kaugnay na mga set ng pag-aaral

WH I Jensen Test #3 (Comprehensive)

View Set

Unit 3 Microeconomics: Fall 2020

View Set

Cell Biology Final Exam Questions

View Set

Advanced Aircraft Systems Quiz 1

View Set