Labs ICT
⭐ Pro Login

Identifying Objects & Classes

Techniques for discovering objects and classes from problem domains.

Finding Objects in the Problem Domain

The first step in OO analysis is identifying the objects and classes that exist in your problem domain. This means reading through requirements, talking to stakeholders, and looking at the real-world processes you're trying to model. Objects are the "nouns" in your system β€” the things that have state and behavior.

A good starting point is to scan requirements documents for nouns. Nouns often represent potential classes, while verbs often represent operations. But not every noun becomes a class β€” you need to filter for things that are relevant to the system and have distinct behavior or state.

Requirements Example:
"Students register for courses. Each course has a maximum capacity.
 Instructors assign grades. The system sends email notifications."

Nouns β†’ Potential Classes:
  Student βœ“    (has state: name, ID; behavior: register, drop)
  Course βœ“     (has state: capacity, schedule; behavior: enroll, cancel)
  Instructor βœ“ (has state: name, department; behavior: assign grade)
  Grade βœ“      (maybe an attribute, not a full class)
  System βœ—     (too vague)
  Email βœ—      (implementation detail, not a domain concept)

Verbs β†’ Potential Operations:
  register   β†’ Student.register(course)
  assign     β†’ Instructor.assignGrade(student, grade)
  send       β†’ NotificationService.sendEmail()

Techniques for Identifying Objects

Several techniques help you systematically discover objects and classes:

1. Noun Phrase Analysis
   ─────────────────────
   Scan requirements for noun phrases.
   "A patient books an appointment with a doctor"
   β†’ Patient, Appointment, Doctor

2. Event Analysis
   ──────────────
   List events that occur in the system.
   "A customer places an order, receives confirmation,
    and can track shipment"
   β†’ Order, Confirmation, Shipment

3. Responsibility Analysis
   ────────────────────────
   Ask: "What responsibilities does the system have?"
   "The system must manage inventory, process payments,
    and generate reports"
   β†’ Inventory, PaymentProcessor, ReportGenerator

4. CRC Cards (Class-Responsibility-Collaborator)
   ──────────────────────────────────────────────
   Create index cards with:
   β€’ Class name
   β€’ Responsibilities (what it does)
   β€’ Collaborators (what it works with)
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Class: Order                        β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Responsibilities:                   β”‚
β”‚  β€’ Track order status               β”‚
β”‚  β€’ Calculate total price            β”‚
β”‚  β€’ Apply discounts                  β”‚
β”‚  β€’ Generate invoice                 β”‚
β”‚                                     β”‚
β”‚ Collaborators:                      β”‚
β”‚  β€’ Customer                         β”‚
β”‚  β€’ OrderItem                        β”‚
β”‚  β€’ PaymentProcessor                 β”‚
β”‚  β€’ InventoryManager                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Filtering Candidates

Not every noun becomes a class. Apply these filters to decide what stays:

Keep as a Class if:
  βœ“ It has attributes that need to be stored
  βœ“ It has behavior (methods) beyond simple getters/setters
  βœ“ It represents a real-world entity or concept
  βœ“ Multiple instances will exist
  βœ“ It interacts with other objects

Discard if:
  βœ— It's a primitive value (just use a string or number)
  βœ— It's a duplicate of an existing class
  βœ— It has no behavior and few attributes (consider making it an attribute)
  βœ— It's an implementation detail (database connection, logger)
  βœ— It's a verb (that's a method, not a class)

For example, in a library system, "book title" is just a string attribute of Book β€” not its own class. But "Book" is definitely a class because it has state (title, author, ISBN, availability) and behavior (checkOut, return, reserve).

Example: Hospital Management System

Let's walk through identifying objects for a hospital system:

Problem Statement:
"The hospital manages patients, doctors, and appointments.
 Patients have medical records. Doctors work in departments.
 The system schedules surgeries and manages billing."

Step 1: Extract nouns
  Patient, Doctor, Appointment, Medical Record, Department,
  Surgery, Bill, Hospital, System

Step 2: Filter and refine
  βœ“ Patient      β€” has records, books appointments
  βœ“ Doctor       β€” has specialties, works in departments
  βœ“ Appointment  β€” connects patient and doctor
  βœ“ MedicalRecord β€” stores patient history
  βœ“ Department   β€” organizes doctors and rooms
  βœ“ Surgery      β€” scheduled procedure with team
  βœ“ Bill         β€” tracks costs and payments
  βœ— Hospital     β€” too broad (the whole system, not a class)
  βœ— System       β€” too vague

Step 3: Define relationships
  Patient ──has──▢ MedicalRecord
  Doctor  ──belongs to──▢ Department
  Appointment ──involves──▢ Patient, Doctor
  Surgery ──scheduled by──▢ Doctor, involves──▢ Patient
  Bill ──generated for──▢ Patient, includes──▢ Services

Pitfalls to Avoid

Common mistakes when identifying objects:

1. God Object
   ────────────
   Making one class do everything.
   "System" or "Manager" that handles all operations.
   β†’ Break it into smaller, focused classes.

2. Anemic Domain Model
   ────────────────────
   Classes that are just data containers with no behavior.
   All logic lives in service classes.
   β†’ Move behavior into the objects that own the data.

3. Analysis Paralysis
   ────────────────────
   Spending too much time trying to find the "perfect" model.
   β†’ Start with a good-enough model and refine as you learn more.

4. Over-engineering
   ──────────────────
   Creating classes for every little concept.
   β†’ Keep it simple. Only create classes that add clear value.

πŸ§ͺ Quick Quiz

Which technique helps identify objects in a problem domain?