Blog Posts
Task 1 Part f)
Design Smells
Task 2
What is it?
Structural design pattern that allow objects to be composed into a tree structure such that individual objects and composites of such objects can be treated in the same way.
When to use?
Model a group of classes that forms a hierarchy
In Unix based operating systems, directories are just files that can contain other files
UML Diagram
Leaf
and Composite
both implement the same interfaceLeaf
and Composite
can be treated as the sameComposite
can hold more than one Leaf
Produces a tree-like structure that leans itself very well towards recursion
Use the composite pattern to design a simple calculator that can be used to evaluate an arithmetic expression.
Your calculator should be able to:
Tree representation
exp1 = 42
exp2 = ((1 + 2) - ((3 / 4) * (5))
UML Diagram
Why use it?
What is it?
Creational design pattern that lets you define an interface for creating objects of a family in a superclass but allows subclasses to alter the type of object that will be created.
Product
declares a common interface to all objects creatable by the Creator
and its subclassesProduct
Creator
to construct new types of productsRefactor the code such that when the characters are created, they are put in a random location in a grid of length of length 5.
In groups, determine a possible design pattern that could used to solve the following problems
1. Sorting collections of records in different orders
1. Sorting collections of records in different orders
Comparator
to Collections.sort
1. Sorting collections of records in different orders
Comparator
to Collections.sort
2. Modelling shapes and the ability to combine shapes
1. Sorting collections of records in different orders
Comparator
to Collections.sort
2. Modelling shapes and the ability to combine shapes
3. Updating a UI component when the state of a program changes.
3. Updating a UI component when the state of a program changes.