Exam tips!
For OOP and Java
Section titled “For OOP and Java”- Make sure you are able to identify and understand four core OOP principles!
- Understand Access Modifiers and know which members are visible outside and inside the class.
- Practice reading code. Don’t just memorize syntax.
- What object is created?
- Which constructor is called?
- What is printed?
- Which methods can be accessed?
- Which relationship exists between these classes?
For identifying relationships:
Section titled “For identifying relationships:”When planning for UML or code, ask yourself these questions:
-
Does one class simply use another? It’s Association
-
Does one class have another, but both can exist separately? It’s Aggregation
-
Does one class own another so it cannot exist independently? It’s Composition
-
Is one class a specialized version of another? It’s Inheritance
-
Make sure you understand the UML symbols by heart and can easily translate UML to English and vice versa!
- E.g. Class A has-a Class B, Class B extends Class C, and Class A uses Class D.
- If you can read a UML diagram like a short story, you’ll have a much easier time answering design and relationship questions on the exam.
Tips for Approaching OOP Design Problems
Section titled “Tips for Approaching OOP Design Problems”When solving object-oriented programming problems, keep these design principles in mind:
- Divide and Conquer: Break a large problem into smaller, manageable classes, each with a specific responsibility.
- Encapsulate Responsibilities: Give each class the data (attributes) and methods (behaviors) it needs to perform its job.
- Design Clear Interfaces: Expose only the methods that other classes need to use, keeping interactions simple and intuitive.
- Hide Implementation Details: Use access modifiers (such as
private) to protect internal data and implementation from other classes. - Keep Classes General: Design classes to solve a type of problem rather than a single specific case so they can be reused.
- Make Classes Extensible: Build classes so they can be extended or specialized without rewriting existing code.
- Focus on Essentials: Model only the attributes and behaviors that are necessary to solve the problem, ignoring unnecessary real-world details.
Rule of thumb: Give each class one clear responsibility, hide its internal details, and let classes cooperate through simple well-defined interfaces and relationships.
Good luck!