Basic concepts

This is a short introduction to classes, which are the basic building blocks of an application.

Classes define categories of data in an application based on "real world" objects. In an application there might be classes like "person", "address", "company", "order" or "product".

In case you are familiair with databases, you can consider a class as a table in a database. To put it another way, a class defines a list of items with the same properties. A person can have a name, address and gender just like a product can be defined by a name, price, catagory and colour.

These properties can be defined in fields. They are like the column names in a table.

Every instance of a class, every person or product in this example, is called a record. In a table these are the rows. The records contain the actual data that will be stored in the database. The following image compares the basic terminology of databases with that of spreadsheets.

 



Key fields

In a database all records need a unique key. Any field that will be absolutely unique in a class can be used as a key field, like a product id. In case there is no such field, you can add a seperate key field that will get unique numbers automatically. It can be considered to hide this field from the view of most of your application's users since in most cases the field will have no meaning to them.


Relationships 

Most applications have more than one class and usually the classes are related, meaning that there are connections between classes.

A relation is always of the type "one-to-many". One record from a specific class can be related to many records in another class. A client can place many orders, but a specific order always belongs to one client. Even though the class Order can contain orders from many different clients, a field in this class can be used to relate every order to the correct client. This field could for example be called ClientId.

In the "one-to-many" relationship, the "one" class is called the foreign class and the "many" class is called the connected class. The following image depicts this relation as a spreadsheet. The highlighted field in the class Order shows the corresponding Id of the client. In this example, the class Client is the foreign class and Order is the connected class.

 

When this connection is depicted in a diagram, the one-to-many structure is shown via the crow's foot.

Classes can function as foreign class or connected class indefinitely, both as foreign class and connected class. However, two classes can not be related to each other, a many-to-many connection is not possible. Or, regarding the diagram, a connection can never have a crow's foot on both sides.

There are situations where this type of connection is needed. An order needs to relate to many products, yet one product can be related to more than one order. In this case an intermediary connected class is required. A standard name for this intermediary class would be Order-Product, a more common name in this example would be Order line.

 


 

In this example the class Order holds information like order date, total costs, and shipping costs. The Order line class holds information about which product has been ordered, and in what quantity. On the other side there is a Product class, which can be connected to multiple orders. These can be traced back through Order line.

Basically, the intermediary connected class holds the list of every connection between products and orders.


Extended data model

This is a model with 6 classes, a possible model for a shop. When data-modelling, visualizing the structure can help to avoid unnecessary or illogical connections.