Tutorial 9
1. Sorting a list of students records in different orders
Comparator that can be passed to Collections.sort
2. Model a collection of toys. Some toys like a Box can store other toys
3. Adjusting the brightness of computer screens based on a light censor
4. Model a VendingMachine that could either be in idle mode, product selection mode or payment mode.
5. Model PacMan where its ability (i.e. speed, strength) can be boosted when it runs over a buff
PacMan. At any given time, it can have different buffs and or multiples of the same buffDesign Patterns are tools used to solve common problems in software
Remember KISS, don't use design pattern if you don't need to
Identify any code smells and underlying design problems
Mark, Bill and Jeff are working on a PetShop application. The PetShop has functionality to feed, clean and exercise different types of animals. Mark notices that each time he adds a new species of animal to his system, he also has to rewrite all the methods in the PetShop so it can take care of the new animal.
Code smell(s):
divergent change
PetShop every time a new animal is addedDesign problem(s):
Two more questions will be done in a code editor
Check the notes on Github
How do code smells cause problems when developing code?
Is a code smell always a sign of a design problem?
No. For example, sometimes message chaining a.getB().getC() is unavoidable