0% found this document useful (0 votes)
20 views22 pages

Week9 DesignPatterns Composite

Uploaded by

Yu Won
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views22 pages

Week9 DesignPatterns Composite

Uploaded by

Yu Won
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 22

Software Engineering

Week 9
Software Engineering
Wk Lecture Practical
1 Introduction Canvas, Assessment Understand the case
Software lifecycle study.
Write the user stories.
2 Work as a group! Agile
Design the database and
Plan the work on Review of the software
the software
the UI and the requirements and design
Set the version control
Use Case Review of the OOP concepts.
diagram.
3 User Stories Git
4 Plan the work on Graphical User Interface. MVC Coding
the user stories pattern. Retrospective
Check if you are on
5 Plan the work on Create and connect the database
track.
the database to the application.
6 Plan the current From UML to C# code
task
7 Plan the current Testing – Manual and Automated
task
8-9 Retrospective. Design patterns More coding.
Plan the current Accomplish the quality.
task. Secure coding.
10 Software Validation and Double check.
Verification No new features.
Enhancements.
11 Software Maintenance.
Learning Outcomes

Learn about the Composite Design Pattern and its


importance.

Be able to identify the situations where the Composite


Design Pattern can be used.
Design Patterns
Creational Structural Behavioral
Abstract Factory Adapter Chain of Responsibility
Builder Bridge Command
Prototype Composite Iterator
Singleton Decorator Mediator
Factory Method Facade Memento
Flyweight Observer
Proxy State
Strategy
Visitor
Interpreter
Template Method
Composite Design Pattern

A few examples….
Problem - Company

In a small organisation, there are 5 employees. At top


position, there is one general manager. The general
manager manages two employees, one is a manager and
the other one is a developer. The manager has two
developers working for him. We want to print the name
and salary of all employees from top to bottom.
General
Manager
Manager Developer

Developer Developer
Problem

A diagram is a structure that consists of Objects such as


Circles, Lines, Triangles etc.
We would like to be able to set the drawing colour and all
the Objects belonging to the diagram to be drawn with the
same colour.
Here, the diagram is made up of different parts and they
all have some common operations.
Problem

A file system is a tree structure that contains branches


which are Folders as well as Leaf nodes which are Files.
A folder usually contains one or more files or folders.
A file is a simple object.
Files and folders have many operations and attributes in
common, such as moving and copying a file or a folder,
listing file or folder attributes such as file name and size.
It is more convenient to treat both files and folders
uniformly as objects.
Problem

Can you think of a similar example?


Problem

What do all these problems have in common?


Problem

The problems above are examples of the composite


design pattern that allows you to have a tree structure
and ask each node in the tree structure to perform a task.
Composite Design Pattern

“Compose objects into tree structure to represent part-


whole hierarchies. Composite lets client treat individual
objects and compositions of objects uniformly."

Gamma, E., Helm, R., Johnson, R., Vlissides, J.,Design Patterns, Elements of Reusable Object-Oriented Software, ISBN 0201633612
Composite Design Pattern

UML Class Diagram

Gamma, E., Helm, R., Johnson, R., Vlissides, J.,Design Patterns, Elements of Reusable Object-Oriented Software, ISBN 0201633612
Composite Design Pattern
Component (Employee)
•declares the interface for objects in the
composition.
•implements default behavior for the interface
common to all classes, as appropriate.
• declares an interface for
accessing and managing
its child components.
• (optional) defines an
interface for accessing a
component's parent in the
recursive structure, and
implements it if that's
appropriate.
http://www.dofactory.com/net/observer-design-pattern
Composite Design Pattern

Leaf (Developer)
•represents leaf objects in
the composition. A leaf has
no children.
•defines behavior for
primitive objects in the
composition.
http://www.dofactory.com/net/observer-design-pattern
Composite Design Pattern

Composite (Manager)
•defines behavior for
components having
children.
•stores child components.
•implements child-related
operations in the
Component interface.

http://www.dofactory.com/net/observer-design-pattern
Composite Design Pattern
Client (the Company)
•manipulates objects in the
composition through the
Component interface.

http://www.dofactory.com/net/observer-design-pattern
Problem - Company

In a small organisation, there are 5 employees. At top


position, there is one general manager. The general
manager manages two employees, one is a manager and
the other one is a developer. The manager has two
developers working for him. We want to print the name
and salary of all employees from top to bottom.
General
Manager
Manager Developer

Developer Developer
Problem - Company

UML Class Diagram

Developer General
Manager
Manager
Company - Implementation

Let’s have a look at the CompositeDesignPattern project.


Reading List

Gamma, E., Helm, R., Johnson, R., Vlissides, J., Design


Patterns, Elements of Reusable Object-Oriented Software,
Addison Wesley, ISBN 0201633612

http://www.dofactory.com/net/design-patterns
Questions

You might also like