Computer Engineering is coming soon

We're still writing and reviewing the notes for every subject, and we'll open it when every subject is ready. Meanwhile you can practise aptitude, ask Aria about any subject, or see the branches that are ready.

Implementation modelling

Implementation modelling is the set of rules and mappings that convert OO analysis/design models (classes, associations, state and component models) into concrete code, files and runtime artifacts used by engineers during coding, build and deployment.

Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.

Why it matters

Implementation modelling is what a software engineer uses to turn design models (class diagrams, component diagrams, state models) into source code, libraries and deployment artifacts. It guides choices such as how to represent associations, inheritance, visibility, and modules so the system is correctly built, compiled and deployed.

Key ideas

Start with definitions. I will define each term before using it.

  • Implementation model — a specification that maps elements of design models (classes, attributes, operations, associations, components) to concrete implementation artifacts (source files, classes in a programming language, modules, libraries, deployment units). It records rules and choices such as file layout, language idioms, and persistence mapping.

  • Artifact — a named, versioned file or binary produced or used during implementation (source file, compiled class, JAR, header file). An artifact is the physical thing that implements a model element.

  • Component — a deployable unit (module, package, service) that groups artifacts and provides/uses interfaces. In implementation modelling this tells which classes live together in a library or executable.

  • Interface — a named set of operation signatures (no implementation) that a class or component exposes. Interfaces separate contract from implementation.

  • Realization / implementation — the relationship where an artifact or class provides the code that satisfies an interface or model element.

  • Mapping — a rule that converts one model element to one or more implementation artifacts (e.g., class → source file, association multiplicity >1 → collection field). A mapping must be precise for code generation or manual coding.

  • Compile-time — the phase when source artifacts are translated to binaries (e.g., Java .java → .class). Bindings decided at compile-time cannot change at runtime unless using reflection or dynamic loading.

  • Run-time — the phase when the program executes; run-time representation (objects, memory layout) is where composition and ownership semantics matter.

Principles and exact statements (universally used in exam answers):

  • Single Responsibility Principle (SRP) — "A class should have only one reason to change." Assumption: reasons to change correspond to distinct responsibilities in requirements. Use SRP when designing which methods/fields belong to a class or module; violations lead to low cohesion.

  • Open/Closed Principle (OCP) — "Software entities (classes, modules, functions) should be open for extension, but closed for modification." Assumption: you can extend behaviour via inheritance, interfaces or composition rather than editing tested code.

  • Law of Demeter (LoD) — "A method M of object O should only call methods of: O itself, objects passed as parameters, objects it creates, or its direct component objects." Assumption: reduces coupling by avoiding chained navigation (a.getB().getC().do()). Exams commonly ask to state LoD and give an example of violating it.

  • Liskov Substitution Principle (LSP) — "Objects of a superclass should be replaceable with objects of a subclass without breaking the program." Assumption: subtypes must honor the behavioral contracts of supertypes.

  • Dependency Inversion Principle (DIP) — "Depend on abstractions, not on concretions." Assumption: high-level modules should not depend on low-level modules; both should depend on interfaces.

Precise mapping rules commonly asked in exams — give exact steps you should write as an answer:

  1. Mapping a class: draw a rectangle labeled with the class name. Map to one source artifact named using language convention (e.g., Java: ClassName.java). Declare attributes as fields and operations as methods with matching visibility.

  2. Mapping attribute types: if attribute type is a class from the model, use the corresponding implementation class name; if primitive, use the language primitive (int, boolean, float) or standard library type (String).

  3. Mapping association:

    • If multiplicity at one end is 0..1 or 1, map to a single reference field (e.g., Customer customer;).
    • If multiplicity is * (0.., 1..), map to a collection (List<Product> items;) or array if fixed-size. For 1..*, enforce the non-empty invariant in constructors or mutators. If the end is ordered or must be unique, choose List for ordered and Set for unique.
    • If association is navigable only from A to B, implement only A having a reference to B.
    • If association is bidirectional, implement references at both ends and keep invariants in methods (add/remove updates both sides).
  4. Mapping aggregation vs composition: composition implies strong ownership: implement with lifecycle management (owner creates/destroys contained objects) and often via private field plus no public setter. Aggregation is a weaker link: allow shared references.

  5. Mapping generalization: map to language inheritance (extends in Java/C++), or to interface + delegation when multiple inheritance is required in a language that does not support it.

  6. Mapping interface: map to language interface or abstract class with abstract methods. Implementation classes implements or extends the interface.

  7. Mapping exceptions and error states: design runtime error types and map state model transitions that throw specific exceptions; document checked/unchecked choices.

Diagrams to draw in exams (describe exactly what to draw and label):

  • To show class→code mapping: draw a small class diagram containing 3 classes (Customer, Order, Product) with associations. Then draw boxes for source files: Customer.java, Order.java, Product.java and arrows from source file boxes to class boxes labelled "manifests".
  • To show bidirectional association: draw two classes A and B with a double-headed association line; annotate multiplicities. Next to each class, draw field declarations B b; and List<A> as; and arrows showing add()/remove() operations updating both sides.

Formulas

class ClassName { /* fields and methods */ } — declare a class (Java/C# style) interface InterfaceName { /* method signatures */ } — declare an interface public/private/protected — access modifiers: public (visible everywhere), private (visible only inside class), protected (visible to subclasses and to any class in the same package in Java; for subclasses in a different package, access is only through inheritance) class Sub extends Super — inheritance (Java/C++ syntax differs: C++ class Sub : public Super) class C implements I — a class implements an interface (Java) List<Type> fieldName; — multiplicity * mapped to a dynamic list (Java) Type[] fieldName; — multiplicity mapped to array when size fixed or performance/interop needed package com.example.module; — package/module declaration (Java) #ifndef HEADER_H #define HEADER_H ... #endif — include-guard pattern in C/C++ headers public ClassName() — constructor syntax (Java/C#) ~ClassName() — destructor (C++); in C#, this syntax declares a finalizer, not a deterministic destructor

Notes: use the syntax appropriate to the target language; in exams, state the language you are mapping to. Also map UML static attributes/operations to 'static' fields/methods in the target language.

Worked examples

Example 1 — Mapping a small class diagram to Java code (step-by-step). Given: Class diagram with classes Customer, Order, Product. Associations: Customer 1..* — places —> Order (one customer can place many orders). Order 1 — contains —> Product (each Order contains exactly one primary Product) and Order 0..* — hasLineItems —> Product (other products). Assume bidirectional Customer–Order navigable from both sides; Order–Product primary is unidirectional.

Steps (numbered):

  1. Map each class to a Java source file: Customer.java, Order.java, Product.java.
  2. For Customer: multiplicity 1..* to Order means Customer has List<Order> orders; and Order has Customer customer; because bidirectional.
  3. For Order primary Product (1) unidirectional: Order has Product primaryProduct; and Product has no reference back. Also map the 0..* hasLineItems association as List<Product> lineItems = new ArrayList<>(); in Order.
  4. Implement add/remove on Customer to maintain both sides:
    • Formula (method skeleton): public void addOrder(Order o) { orders.add(o); o.setCustomer(this); } — be careful to avoid cycles or duplicates (check contains() and handle reassignment).
  5. Code skeleton (show important lines): // Order.java public class Order { private Customer customer; private Product primaryProduct; public void setCustomer(Customer c) { this.customer = c; } } // Customer.java public class Customer { private List<Order> orders = new ArrayList<>(); public void addOrder(Order o) { if (!orders.contains(o)) { orders.add(o); } o.setCustomer(this); } public void removeOrder(Order o) { if (orders.remove(o)) { o.setCustomer(null); } } }

Final answer (exam style): list files, show field declarations, show two methods addOrder/removeOrder with both-side update. Explain why composition would change add/remove semantics (owner destroys contained orders).

Example 2 — Inheritance and interface mapping (step-by-step trace). Given: Model has abstract Payment with operation process(), and Refundable interface. Concrete classes: CreditCardPayment (refundable) and CashPayment (not refundable).

Mapping steps:

  1. Payment → Java public abstract class Payment { public abstract void process(); }.
  2. Refundable → public interface Refundable { void refund(); }.
  3. CreditCardPayment → public class CreditCardPayment extends Payment implements Refundable { public void process() { ... } public void refund() { ... } }.
  4. CashPayment → public class CashPayment extends Payment { public void process() { ... } }. Explain: this mapping supports polymorphism: code can accept Payment p and call p.process(). To refund, test if (p instanceof Refundable) ((Refundable)p).refund();.

Common mistakes

  • Mapping multiplicity * to a plain array when dynamic addition/removal is required without showing resizing logic.
  • Using inheritance when composition is better (violates SRP and increases coupling).
  • Confusing aggregation and composition: not enforcing lifecycle (composition should show owner creates/destroys child).
  • Exposing internal mutable collections directly (returning the list field) instead of returning an unmodifiable view or copy.
  • Not declaring visibility correctly: using public fields instead of private with accessors.

For your exam

Typical question types:

  • Definitions and short notes (define implementation model, artifact, component).
  • Diagram drawing and mapping (map a given class diagram to source files and show code skeletons).
  • Procedure/derivation (step-by-step rules to map associations, multiplicities, and generalization).
  • Code-writing/tracing (implement small class skeletons, show add/remove maintaining invariants).
  • Design rationale (justify choice of collection, use of interface vs abstract class, lifecycle management).

What full-marks answers include:

  • Clear statement of assumptions (target language, single-threaded vs concurrent, persistence required?).
  • Exact mapping rules (class→file, multiplicity→collection or array, navigability→reference placement).
  • Diagrams where requested (label classes, artifacts, arrows and multiplicities exactly).
  • Code skeletons using correct syntax of declared language; show access modifiers and key methods.
  • Notes on invariants and lifecycle (how owners manage composed objects, update both sides of bidirectional links).

Quick check

  1. What implementation artifact maps to a UML class in Java?
  2. How do you represent a 1..* multiplicity in an implementation?
  3. State the Single Responsibility Principle in one sentence.

Answers: 1) A source file (ClassName.java) containing the class implementation. 2) As a collection field (e.g., List<Type> field;) or array if fixed-size, with methods to add/remove; if multiplicity is 1..*, enforce non-empty. 3) "A class should have only one reason to change."

Finished this topic? Mark it so your progress, study plan and readiness keep up.

Stuck on something here?