Notes - Object-oriented Programming (OOP) - ver1-part2
Draft discussed and generated with ChatGPT, then edited through personal understanding.
This article is intended as a learning record.
Mapping Semantic(Meaning) to Object Models
The previous article only explained the basic definitions of the elements in Object-oriented programming, but in practice, it usually starts from mapping Semantic into the required program.
Various AI tools (conversational AI) can directly perform the task of mapping Semantic into object models.
1. Semantic(Meaning)
In this document, Semantic(Meaning) refers to 「the meaning expressed by language」.
1.1 Semantic(Meaning) and “Business Semantic”
Semantic(Meaning)
🎯 Metaphor
Semantic is like the intention of a letter — although the words are clear, the real intent depends on context, the recipient’s background, and the situation.
📘 Explanation
Semantic refers to the analysis of a statement’s intention, logical structure, and function.
Requirements can come from:
- Verbal descriptions (requirement discussions, etc.)
- Analysis or planning documents (presentation summaries, specification drafts, planning briefs)
- Specification documents (API specs, standards, contract models)
Business Semantic
「Business Semantic」 refers to the linguistic logic used within a company to express 「business concepts」. For example, each department may have different interpretations and focuses regarding an order.
The goal is to transform 「requirements」 into software as expected through 「consistent understanding」.
Establishing Consistent Semantic
In collaborative environments, it’s necessary to use clear mechanisms to 「align」 Semantic and maintain 「consistency」:
-
Glossary:
Based on usage scope, define nouns and terminology such as customer, order, approval, etc., as reference standards.
Use consistent terminology across names, from requirements to models, for easy identification. -
Collaboration Tools:
Use interactive tools (like Figma, Miro, BPMN workflows) for cross-department validation, allowing participants to directly manipulate and simulate models. This process helps gradually align Semantic within the model.
Semantic from High-Level to Low-Level Concepts
| Level | Characteristics | Common Sources | Description |
|---|---|---|---|
| High-Level | Vague, abstract, scope-oriented | Epics, Features, User Stories, Interviews, Requirement meetings | Requires analysis, decomposition, and logical inference |
| Mid-Level | Structured but still needs details | Specification documents, process diagrams | Can be preliminarily converted into model drafts |
| Low-Level | Clear, structured models | UML models | Can be implemented in code |
1.2 Mapping Semantic to Model Elements
Map Semantic to model elements and align (bidirectional mapping).
After mapping, validate both directions.
Classification of Semantic and Corresponding Model Elements
| Semantic Type | Description | Corresponding Model Elements |
|---|---|---|
| Entity | The subject with behavior | Class, Abstract Class |
| Behavior | Callable or describable actions | Methods, Constructor |
| Attribute | States or descriptive data | Attributes (value type, Class, collection type) |
| Constraint | Business rules, conditions, or state transitions | Internal logic, validation, or state transition logic |
Example: 「A user logs into the system. If the account is already bound to Google, they can log in quickly; otherwise, verification is required.」
| Semantic Type | Semantic Fragment | Description | Corresponding Model Element | |---------------|----------------------------|--------------| | Entity | Account (User) | Has state (bound or not) and behaviors (login, bind) | Class | | Behavior | Login, Quick Login, Verify | Each action has its own logic | Method | | Attribute | Is Google Bound | Affects quick login logic | Attribute (value type) | | Constraint | If not bound, must verify | Logic branch in method | Conditional logic (if-else) |
Identifying Class, Abstract Class, Interface
「Entities」 in Semantic can be converted into Class or Abstract Class.
| Semantic Fragment | Description | Corresponding Model Element |
|---|---|---|
| The calendar includes tasks and reminders | Calendar is an 「entity」 with states and behaviors | Class |
| Both regular users and admins are users | User can 「refer」 to multiple entities sharing 「common logic」 | Abstract Class |
| Exportable, Printable, Notifiable | Represents capabilities or behavioral contracts without attributes | Interface |
Identifying Method
「Actions」 or 「described actions」 in Semantic can be converted into 「methods」.
Consider:
- The 「subject」 of the action: Class/Abstract Class/Interface
- The action and its conditions: reflected in method names and logic
- Related or dependent nouns describing 「conditions」 or 「results」: variables, parameters, return values, possibly representing data or another Class
- Use UML relationships for dependent or associated Class
| Semantic Fragment | Description | Code Style |
|---|---|---|
| User creates a task | User is an Class, create task is a method | User.createTask() |
| If notification is enabled, send message | If enabled is a conditional meaning; send message is a method | sendIfEnabled() |
| Search orders within a time range | Time range is input, Order is output, Search is the method | search(start, end): Order |
Identifying Constructor
If Semantic contains 「create」, 「new」, or 「generate」 + 「entity」, it usually maps to a Constructor.
| Semantic Fragment | Description | Code Style |
|---|---|---|
| Create and name a new task | Task is an 「entity」 with input for name | new Task(name) |
| Create default account | Account is an 「entity」 with default parameters | new User(default) |
Identifying Attribute
Attributes can be:
- Class: entity, using UML relationships
- Value: data, non-entity
- Collection: contains multiple entities or values
| Semantic Fragment | Description | Code Style |
|---|---|---|
| Task title is text | Text is a value | title: String |
| Task has an owner | Owner is an Class | owner: User |
| Reminder times are multiple | Multiple times is a collection (value) | notificationTimes: List<DateTime> |
| Order contains multiple products | Products are a collection (Class) | items: List<Product> |
1.3 Determining UML Relationships from Semantic
In Semantic, when both subject and object are entities, they correspond to UML relationships.
Example Steps
Two entities have an 「instance relationship」:
-
Is it a 「one-way」 「use」, 「trigger」, or 「temporary relationship」?
- Yes → Use Dependency (meaning “use”).
- No → Continue.
-
Does it imply a 「part-whole」 or 「composition」 meaning?
- No → Use Association (persistent relationship, lifecycle independent).For example, it is used in properties that can be nullable.
- Yes →
- Can the referenced entity be shared by multiple entities?
- Yes → Use Aggregation (meaning 「has a」).
- No → Use Composition (meaning 「is a part of」, child cannot exist independently).
- Can the referenced entity be shared by multiple entities?
Two entities have a 「Class hierarchy」 relationship:
-
Is the meaning 「is a kind of (is a)」?
- Yes → Use Generalization.
-
Does one entity 「provide concrete implementation」, 「realizes」?
- Yes → Use Realization.
Other cases:
-
If multiple conditions apply
- Check for potential hidden entities.
- If yes → separate them and re-evaluate relationships.
- If no → discuss or clarify meanings to resolve conflicts.
-
If ambiguous
- Use Association temporarily; refine later or discuss.
Is there a strict priority rule for determining relationships? There are multiple valid answers—it may depend on how quickly you can infer from Meaning or existing definitions, or by referencing existing modules or known design patterns.
Mapping of UML Relationships and Entity Types
| Semantic Fragment | Description | Entity A (Structure Owner) | Entity B (Referenced) | UML Relationship |
|---|---|---|---|---|
| Login service references auth service | references means 「use」 | LoginService (Class/Abstract Class) | AuthService (Class/Abstract Class/Interface) | Dependency |
| Customer purchases product | Existence relationship | - | - | Association |
| Order contains multiple products | Order has products, products not dependent on order | Order (Class) | Product (Class) | Aggregation |
| Task includes subtasks | Subtasks cannot exist independently | Task (Class) | Subtask (Class) | Composition |
| Regular user and admin are users | are is 「is-a」 and inherit basic functions | User (Class/Abstract Class) | Admin/RegularUser (Class) | Generalization |
| Report supports export and print | supports means implementation | Report (Class/Abstract Class) | Export/Print (Interface) | Realization |
1.4 Workflow Separation by Semantic Concept Layer
1. Concept Layer
- Source: User stories, interview notes, requirement discussions.
- Input Conditions:
- Sentences contain clear entities and action meanings.
- 「Who did what」 can be identified in conversations or records.
- Output: Semantic Marking Table: Entities, actions, data, and constraints.
2. Alignment and Transformation Layer (Analysis & Planning)
- Source: Semantic classification table, glossary, temporary notes, prior designs.
- Input Conditions:
- Entities mapped to model elements (Class, attributes).
- Action meanings transformed into methods, I/O data, and constraints.
- Cases:
- If Semantic has unmapped elements → return to Concept Layer.
- If data types are unclear → use generic types (string).
- Migration of existing models corresponds to design and process.
- Output: UML draft diagrams.
3. Design Layer
- Input Conditions:
- All Semantic within the scope classified (Class / attributes / methods / relationships).
- Output: UML documents or equivalent design documents.
Tools and Document Descriptions
| Tool / Document Type | Usage Stage | Format Description | Standard Reference |
|---|---|---|---|
| Semantic Marking Table | Concept Layer | Columns: Semantic fragment, entity, action, attribute, constraint, relation | - |
| UML Draft Diagram | Alignment and Transformation Layer | Simplified UML diagram | UML 2.5.1 |
| Semantic/Structure Mapping Table | Cross-Layer | Columns: Semantic fragment, corresponding element, reasoning, confirmation | - |
| Model Migration Mapping Document | Design Layer | Columns: Version, change summary, affected elements, reasons, reviewer, verification status | - |
| UML Document | Design Layer | Based on UML 2.5.1 standard | UML 2.5.1 |
| Notes | - | Unstructured semantics, unmodeled fragments, ambiguous semantic choices and their alternative judgment basis | Draft notes |
Thank you for reading!