🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
Object-oriented programming
This page was created by Wikiadmin on 2026-07-29. Last edited by Wikiadmin on 2026-07-29.

Object-oriented programming (OOP) is a way to design software as interacting objects, and it is for MDriven users who model a domain with classes, attributes, behavior, and relationships.

Objects and classes

An object is a specific instance of a class. A class defines the common attributes, behavior, relationships, and meaning shared by a group of objects.

For example, a Car class can define attributes such as Make, Model, and Color. A red 2019 Honda Civic is one object of that class. It has its own attribute values while following the structure defined by Car.

Term Meaning Example
Class A blueprint for objects with common structure and behavior. Person
Object One instance of a class, with its own state. A person whose name is Anna and age is 32
Attribute A property defined by a class. Person.Age
Behavior An operation that an object can perform. A Car accelerates or brakes.

Objects can represent real-world entities or concepts. For example, a sales model can contain Customer, Order, and Product classes. Each order object can refer to its customer and contain its order lines.

Relationships between objects

Object-oriented models express how objects relate to each other. A relationship can connect one object to another object or to a collection of objects.

For example, an Order can have many OrderLine objects, while each OrderLine belongs to one Order. Model this relationship rather than maintaining separate lists and pointers in application code. The model defines the relationship at both ends.

Associations also make the domain language visible in the model. Use names from the business domain. For example, name the relationship OrderLines and Order, rather than using technical names that hide what the relationship means.

Inheritance

Inheritance lets a subclass reuse the attributes and associations of a superclass. The subclass can then add properties or associations that apply only to its more specialized meaning.

For example, Fruit can be a superclass with common attributes. Apple and Orange can be subclasses. If all fruits have an association to the countries where they grow, define it on Fruit. Both Apple and Orange then inherit it.

In UML terminology, use superclass and subclass. MDriven uses UML and is implemented using C#. A class can have one superclass or no superclass; MDriven does not support multiple inheritance.

Object-oriented programming in MDriven

In MDriven, you describe the domain as a UML model. MDriven Designer uses classes, attributes, associations, and inheritance to express the structure of the application. This keeps requirements close to the implementation: a class named Order remains an order throughout the model, rather than becoming a set of unrelated technical structures.

You can use OCL (Object Constraint Language) expressions to navigate objects, calculate values, and state rules. For example, the following invariant requires every Person object to be at least 18 years old:

context Person inv: self.age >= 18

Here, self means the current Person object and age is its attribute. See OCL operators for operators used in object expressions.

Objects and persistence

Object-relational mapping (ORM, also called O/R mapping) connects the object-oriented model to a relational database. The mapper converts between objects in the application and rows in database tables.

For example, a Customer class can map to customer records in a database. When you create a customer object, the ORM can persist it as a record. When you navigate from a customer to its orders, the ORM handles the corresponding database relationship.

This lets you work with objects and their relationships while the mapper performs the database operations needed to create, read, update, and delete data.

Object and value types

An object has identity and is usually mutable: changing an attribute changes that same object. Assigning an object to another variable assigns a reference to the object.

A value represents a quantity or state, such as a number, Boolean value, or string. Assigning a value creates a copy. For example, assigning the number 10 to two variables gives each variable its own value, while assigning the same Person object to two variables lets both variables refer to the same person.

In MDriven's OCL implementation, String is not an object. When an OCL operator requires an object parameter, a string is not a valid object parameter.

See also