MTRN2500
Week 10 Lab01
WEDNESDAY 4PM - 6PM
THURSDAY 4PM - 6PM
Slides by Alvin Cherk (z5311001)
Today
- Know the factors that makes code maintainable.
- Understand the relationship between cohesion and coupling and how this affects code maintenance.
- Know what relevant code smells exist (i.e. bloaters, dispensables, shotgun surgery).
- Can identify common code smells within a program.
- Can refactor common code smells.
Smells
Smells
Code smells are code and coding patterns that is considered bad style as a result of poor programming.
Design smells, on the other hand, tend to be more subtle. They usually affect maintainability and flexibility although symptoms of a poor design can also include unclear or misleading code.
Smells
Code smells negatively impact the maintenance of a program i.e. it decreases:
- Readability: The effort required to read and understand a program's behaviour.
- Flexibility: The ability to change a program.
- Extensibility: The ability to add features to a program.
- Robustness: The resilience of the program to breaking (especially when changes are made).
- Reusability: The effort required to reuse a program component in another system.
Refactoring
Refactoring
Why is writing good code important?
We write code for other people whether they are collaborators or clients therefore our code must be readable and maintainable by other people.
Unmaintainable code costs money, time, and effort to fix or add features to.
Refactoring
The process of restructuring software to make it easier to understand and cheaper to modify without changing its external, observable behaviour.
When should you refactor?
- Improves design of software
- Easier to understand
- Find bugs
- Program faster
- Conform to design principles and avoid design smells
Characteristics of Good Design
Coupling & Cohesion
Coupling & Cohesion
Good software aims for building a system with loose coupling and high cohesion among its components so that software entities are:
- Extensible
- Reusable
- Maintainable
- Understandable
- Testable
Coupling
- Coupling is defined as the degree of interdependence between components or classes
- High coupling occurs when one component
A
depends on internal workings of another componentB
and is affected by internal changes to componentB
- High coupling leads to a complex system
Aim for loosely coupled classes. It allows components to be used and modified independently of each other
Cohesion
- The degree to which all elements of a component or class or module work together as a functional unit
- Highly cohesive modules are much easier to maintain and less frequently changed and have higher probability of reusability
- Think about
- How well the lines of code in a method or function work together to create a sense of purpose?
- How well do methods and properties of a class work together to define a class and its purpose?
- How well do the classes fit together to create modules?
Coupling & Cohesion
Coupling & Cohesion
The outside system (Server Layer, BookingSystemTest, CLI Wrapper) is lowly coupled with the overall Booking System.
Communication between the outside & internal system is just done via the BookingSystemController
MTRN2500 Week 10 Lab 1 22T3
By kuroson
MTRN2500 Week 10 Lab 1 22T3
- 219