Design Techniques Flashcards
Design Technique: Documentation
Main focus on readability:
- code documentation and comments
- code style conventions and restrictions of language features
- good naming of identifiers
What are API comments?
comments on class level and method level
- add useful information for developers
- > describe in detail when method is called, its behaviour (side effects, exceptions, etc), additional restrictions
What are Statement level comments?
Describe implementation details for own code
Design Technique: Refactoring
technique for restriction an existing body of code without changing its external behaviour
- preparing addition of features
- improving design (eg. cohesion) and maintainability
- increase comprehensibility
Refactoring Technique: Extract Method
When?
- one method does many things
- code duplication within the method itself or across several methods
Refactoring Technique: Extract Method
Worauf achten?
Variables:
- ensure that they are only used in the extracted
code
-> declare them locally
- exactly one variable is modified in code
-> check if it can become the return value
- more than one var is modified
-> method not applicable
Refactoring Technique: Move Method
When?
Class has too many responsibilities
-> split them into different classes (SRP)
Refactoring Technique: Move Method
Check
Does the source method
- use features of the source class
- override method or is overriden
Refactoring Technique: Extract class
When?
if class has two or more independent responsibilities and no other class is suitable for the fields and methods