Java Programming - Object-Oriented Design
Object-Oriented Design
Method Design
- High-level design issues:
- Identifying primary classes and objects.
- Assigning responsibilities.
- Low-level issue: Design of methods for efficiency and elegance.
Method Decomposition
- Methods should be small and understandable.
- Large methods can be decomposed into smaller methods for clarity.
- Example: Translating English to Pig Latin involves multiple decompositions:
- Translating each word.
- Handling words by categories (e.g., starting with vowels, consonants, blends).
Visibility in UML Class Diagrams
- Public members: +
- Private members: -
Example: Pig Latin
- Implementation shows method decomposition in action.
- Involves main method for reading input and translating sentences.
Objects as Parameters
- Java passes parameters by value (copies).
- When objects are passed, the actual and formal parameters are aliases.
Method Overloading
- Single method name can have multiple definitions based on parameters.
- Signature must be unique (number, type, order of parameters) to determine the method invoked.
- Examples:
println(String s)
, println(int i)
.
Testing
- Various definitions: executing programs, human evaluations, finding errors.
- Reviews enhance design or code quality via outside perspectives.
- Test cases involve sets of inputs with expected results; organized into suites.
- Types of testing:
- Defect Testing: Executing to find errors.
- Black-Box Testing: Based on inputs and expected outputs without logic consideration.
- White-Box Testing: Focuses on internal code structure to test all paths.
Conclusion
- Effective design involves method decomposition, parameter handling, and thoughtful testing strategies for quality assurance.