Class
A class is the blueprint that declares the state slots and methods an object should have. Even when many objects exist at runtime, the class is what defines the structure and behavior they share.
βΆArchitecture Diagram
π StructureDashed line animations indicate the flow direction of data or requests
When the same kind of entity is created ad hoc in many places, field requirements and behavior rules drift apart. One user object ends up with different property names than another, and creation rules stop being consistent across the system.
Early object-oriented languages such as Simula and Smalltalk were trying to model real-world entities by keeping state and behavior together. Classes became the core mechanism because functions and records alone were not enough to describe a stable shared design for many related runtime instances.
A class holds field declarations and method definitions together. When instances are created, each object gets its own state, but the available methods and initialization rules are shared from the same class definition.
Class and object are closely related but not the same thing. A class is the shared design, while an object is the concrete runtime realization of that design with actual values and identity.
Classes are especially useful when the same kind of entity appears repeatedly, such as users, orders, sessions, or documents. If you only need a small immutable value with no lifecycle or behavior, turning it into a class can make the design heavier than necessary.