Object Orientation
1. Why OOP??
- OOP helps to keep the Java code DRY "Don't Repeat Yourself"
- Makes the code easier to comprehend, maintain, modify and debug
2. OOP Terms (1 of 3)
Key terms used when describing Object Oriented Programming/Designing.

2.1. OOP Terms (2 of 3)
| Term | Description | Use Case |
|---|---|---|
| Encapsulation | Bundling data and methods together while restricting direct access to some components. | Hiding internal state and exposing only necessary API methods (e.g., getBalance()). |
| Abstraction | Hiding complex implementation details while exposing essential features. | Providing a simple interface like pay() without showing internal payment logic. |
2.2. OOP Terms (3 of 3)
| Term | Description | Use Case |
|---|---|---|
| Inheritance | Allowing one class to derive from another and reuse its behavior. | Employee class inheriting from a Person class. |
| Polymorphism | Ability for different classes to respond differently to the same method call. | draw() behaving differently for Circle, Square, and Triangle classes. |
3. Class Structure (1 of 2) :: Class, Object and new keyword
| Term | Description | Use Case |
|---|---|---|
| Class | A blueprint that defines the properties (attributes) and behaviors (methods) of objects. | Used to model real-world entities such as Car, User, or Invoice. |
| Object | An instance of a class containing actual data. | Creating a specific User object from a User class with unique data. |
The new keyword, creates an Object ("a living copy") of a Class ("a blueprint/template" of Java code grouping). |
3.1. An example :: a class

We do new MethodDemo() to create an instance (an Object) of the this class.
3.2. Class Structure (2 of 2) :: Constructors & Destructors
| Constructor | A special method called when an object is created to initialize it. | Setting default values when creating a new Order. |
|---|---|---|
| Destructor | A method called when an object is destroyed or goes out of scope. | Releasing resources or closing files in languages that support destructors. |
4. Methods and Members/Fields
| Term | Description | Use Case |
|---|---|---|
| Attribute (Field) | A variable inside a class that stores data for objects. | name, age, or balance inside a Customer class. |
| Method | A function defined inside a class to perform actions. | deposit(), drive(), or login() actions. |
5. "Type Contracts" :: Abstract classes and Interfaces
| Term | Description | Use Case |
|---|---|---|
| Abstract Class | A class that cannot be instantiated and may contain abstract methods. | Base class for shared logic with required methods, like Animal with an abstract makeSound(). |
| Interface | A contract listing methods a class must implement without providing implementation. | Ensuring multiple classes share consistent behavior like Serializable or Drawable. |
6. Code Organisation
| Term | Description | Use Case |
|---|---|---|
| Namespace / Package | Containers for organizing related classes. | Grouping utility classes under utils or math. |
7. Behaviour Modification
| Term | Description | Use Case |
|---|---|---|
| Overloading | Defining multiple methods with the same name but different parameters. | add(int, int) and add(double, double). |
| Overriding | Redefining a method from a parent class in a child class. | Customizing toString() or overriding move() in subclasses. |
8. Relationships
| Term | Description | Use Case |
|---|---|---|
| Association | A relationship where two classes interact but neither owns the other. | Teacher teaches Student. |
| Aggregation | A “has-a” relationship where one class contains another, but both can exist independently. | Team has Players. |
| Composition | A strong form of aggregation where the contained object cannot exist independently. | House composed of Rooms. |
is-a vs has-a :: Inheritance vs Composition/Encapsulation
Inheritance


9. References
Object-Oriented-Programming Concepts in Java | Baeldung https://www.baeldung.com/java-oop
Java OOP(Object Oriented Programming) Concepts - GeeksforGeeks https://www.geeksforgeeks.org/java/object-oriented-programming-oops-concept-in-java/
Java OOP (Object-Oriented Programming) https://www.w3schools.com/java/java_oop.asp
OOP Exercises - Java Programming Tutorial https://www3.ntu.edu.sg/home/ehchua/programming/java/J3f_OOPExercises.html
Java OOP Cheat Sheet: Object Oriented Programming Concept Codes https://www.edureka.co/blog/cheatsheets/java-oop-cheat-sheet/