Master Object-Oriented Basics: Objects, Classes, UML & Core OOP Principles
This article introduces fundamental object‑oriented concepts—including objects, classes, abstraction, interfaces, the three OOP pillars, class relationships, and UML class diagram basics—to build a solid foundation for future design‑pattern studies.
Abstract This article introduces basic object‑oriented concepts such as objects, classes, abstraction, interfaces, the three main OOP features, and fundamental UML class diagram knowledge, serving as a foundation for subsequent articles.
1. Objects and Classes
1.1 Object In OOP, everything is an object—animals, plants, a cup, a bowl—each representing a real, tangible entity.
Describing things as objects aligns better with human thinking than procedural approaches.
1.2 Class A class abstracts objects; for example, a dog and a cat belong to the abstract class Animal .
1.3 Relationship A class is an abstraction of objects, while an object is an instance of a class. One class can have many objects, but an object typically belongs to a single class. UML provides class diagrams and object diagrams.
1.4 Thought Process Identify commonalities among objects and group them into a class (e.g., Zhang San and Li Si are objects of the class Person ).
1.5 Class Composition A class mainly consists of attributes and methods (members). For example, class Person may have attributes name, age and methods walk(), run().
1.6 Important Class Concepts
(1) Instantiation: creating an object, usually with new, e.g., Person tom = new Person(); (2) Constructor: a default or custom method for initializing member variables.
(3) Overloading: multiple methods with the same name but different parameter lists.
(4) Overriding: a subclass redefines a parent class method (keyword override) to achieve polymorphism.
public void hello() {
}
public void hell(String name) {
}
public void hello(int index) {
}1.7 Interface An interface defines a contract without method bodies; classes implement interfaces to achieve loose coupling.
A class can implement multiple interfaces but can inherit only one class.
1.8 Abstract Class Declared with abstract, it can contain both abstract methods and concrete implementations, useful for shared code across multiple subclasses.
2. Three Main OOP Features
2.1 Encapsulation Bundles related data and behavior inside a class, exposing only necessary methods, which hides internal details and improves cohesion.
2.2 Inheritance Establishes a parent‑child relationship where a subclass inherits public and protected members of its superclass, enabling code reuse.
Potential issues include inheriting unnecessary behavior and deep inheritance hierarchies that complicate maintenance.
2.3 Polymorphism Allows multiple implementations of an interface, shielding differences between classes and enhancing flexibility and extensibility.
Problems may arise if implementing classes do not follow the interface contract or if complexity increases.
3. Relationships Between Classes
3.1 Generalization Represents an inheritance (is‑a) relationship.
3.2 Association A reference relationship, which can be dependency, aggregation, or composition.
Dependency: one element needs another (e.g., a person needs air).
Aggregation: a weak whole‑part relationship where lifecycles differ (e.g., birds and a flock).
Composition: a strong whole‑part relationship with shared lifecycle (e.g., a car and its engine).
3.3 High Cohesion & Loose Coupling High cohesion means class internals are closely related; loose coupling minimizes unnecessary dependencies, often achieved via interfaces, aggregation, or composition.
4. General OOP Process
1) Identify objects 2) Abstract classes 3) Define class attributes 4) Define class relationships 5) Design review
5. UML Class Diagram Basics
5.1 Basic Elements
Class diagram includes class name, attributes, and methods. Visibility modifiers include protected and default (internal).
5.2 Relationships
Association: mutual usage between A and B.
Dependency: changes in B affect A.
Aggregation: A contains B, but B can exist independently.
Composition: A contains B, and B’s lifecycle is bound to A.
Generalization: inheritance relationship (class or interface).
Implementation: relationship between an interface and its implementing class.
Next Article Preview
Review of Design Patterns Series (Part 3): Object‑Oriented Design Principles – covering code abstraction principles, GRASP, SOLID, and SOC.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
ITFLY8 Architecture Home
ITFLY8 Architecture Home - focused on architecture knowledge sharing and exchange, covering project management and product design. Includes large-scale distributed website architecture (high performance, high availability, caching, message queues...), design patterns, architecture patterns, big data, project management (SCRUM, PMP, Prince2), product design, and more.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
