Software Construction: Object-oriented programming basics
Some basic OO-principles.
Some basic OO-principles.
Fichier Détails
Cartes-fiches | 13 |
---|---|
Langue | Deutsch |
Catégorie | Informatique |
Niveau | Université |
Crée / Actualisé | 30.12.2019 / 11.01.2020 |
Lien de web |
https://card2brain.ch/box/20191230_software_construction_objectoriented_programming_basics
|
Intégrer |
<iframe src="https://card2brain.ch/box/20191230_software_construction_objectoriented_programming_basics/embed" width="780" height="150" scrolling="no" frameborder="0"></iframe>
|
The law of continuing change
A large program that is used undergoes continuing change or becomes progressively less useful. The change process continues until it is judged more cost-effective to replace the system with a recreated version.
What should design optimize?
Enable small, incremental changes by designing software around stable abstractions and interchangeable parts.
How do we find the right design?
Object-oriented design is an iterative and exploratory process. Don’t worry if your initial design is ugly. If you apply the OO design principles consistently, your final design will be beautiful!
What counts as object?
Every domain concept that plays a role in the application & assumes a responsibility is a potential object in the software design.
Responsibility-Driven Design
Well-designed objects have clear responsibilities.
Objects are responsible to maintain information & provide services.
Drive design by asking:
- What actions is this object responsible for?
- What information does this object share?
Every method should perform one, well-defined task.
A good design exhibits:
- high cohesion of operations and data within classes
- low coupling between classes and subsystems
The Single Responsibility Principle
An object should have no more than one key responsibility.
Three views of object-oriented programming
- The Scandinavian view is that an OO system is one whose creators realize that programming is modeling.
- The mystical view is that an OO system is built out of objects that send messages to each other, and computation is the messages flying between objects.
- The software engineering view is that an OO system is one that supports data abstraction, polymorphism by late- binding of function calls, and inheritance.
What is object-oriented programming? (5 points)
- Encapsulation
- Composition
- Responsibility Distribution
- Message Passing
- Inheritance
Object-oriented design in a nutshell (5+1 points)
- Identify minimal requirements
- Make the requirements testable
- Identify objects and their responsibilities
- Implement and test objects
- Refactor to simplify design
- Iterate!
Design by Contract
Formalize client / server contract as obligations.
Class invariant formalize valid state.
Pre- & post-conditions on all public services:
- Clarifies responsibilities
- Simplifies design
- Simplifies debugging
Refactoring (Definition)
Refactoring is the process of rewriting a computer program or other material to improve its structure or readability, while explicitly keeping its meaning or behavior.
- Renaming methods, variables and classes
- Redistributing responsibilities
- Factoring out helper methods
- Pushing methods up or down the hierarchy
- Extracting class
Code smells
- Duplicated code
- Long methods
- Large classes
- Public instance variables
- No / useless comments
- Unreadable code
Testing
- Formalize requirements
- Know when you are done
- Simplify debugging
- Enable changes
- Document usage