08 - Ch8 Implementation - 2022 - Ny
08 - Ch8 Implementation - 2022 - Ny
ENGINEERING
CO3001
WEEK 8
Adapted from https://iansommerville.com/software-engineering-book/slides/
TOPICS COVERED
Implementation meaning
Coding style & standards
Code with correctness justification
Integration meaning
Integration process
Properties
Preserve correctness
One step at a time
Frequent testing
CODE REFACTORING STEPS
Long Method
E.g., Extract method
Large Class
E.g., Extract class, subclass, interface
EXTRACT METHOD EXAMPLE
If you have to spend effort looking at a fragment of code and figure out what it
is doing, then you should extract it into a function/method and name it after
“what.”
Code smell
One module is often changed in different ways for different
reasons.
Classes have more than distinct responsibilities that it has
more than one reason to change
Violation of single responsibility design principle
Refactoring
You identify everything that changes for a particular cause
and put them all together
INCREASE COHESION
Feature envy
A function in one module spends more time communicating
with functions or data inside another module than it does
within its own module.
Move function to give it a dream home
https://waog.wordpress.com/2014/08/25/code-smell-feature-envy/
INCREASE COHESION (CONT’)
• Data clumps
– Bunches of data often hang around together
– Consolidate the data together, e.g., Introduce
Parameter Object or Preserve Whole Object
https://codeburst.io/write-clean-code-and-get-rid-of-code-smells-aea271f30318
We create a new class called Address
Every time we need to add/edit an
address we hit the Address class
https://codeburst.io/write-clean-code-and-get-rid-of-code-smells-aea271f30318
INSPECTION AND CODE REVIEW
Testing Inspection
MB1. Is the algorithm consistent with the detailed design pseudocode and/or flowchart?
MB2. Does the code assume no more than the stated preconditions?
MB3. Does the code produce every one of the postconditions?
MB4. Does the code respect the required invariant?
MB5. Does every loop terminate?
MB6. Are required notational standards observed?
MB7. Has every line been thoroughly checked?
MB8. Are all braces balanced?
MB9. Are illegal parameters considered?
MB10. Does the code return the correct type?
MB11. Is the code thoroughly commented?