Daniel Sapoundjiev on
Object model in software applications
What we are talking about
There are different meanings for object model, so I will explain about what I am going to write here.
Object model is collection of objects. Not classes. Objects that live in software applications and have some connections between them. By connections I mean some object references. Object model can represent something from real life or idea. Such as a paper with drawing. Or machine. Object model consists of objects and list of objects
What is inside the object model?
Tipicaly object model looks like that. One main object that has references to other objects and lists of other objects. The other objects in the main one have references to other objects and lists of objects. So it looks like a tree of objects.
Main object in the model
We need one main object to identify the model. In software applications objects are the real existing instances of the class. So, everything that is in this main object will be part of the model. And we can reference a model by its main object.
What happens with the object model during its life
The main object is created. Then other objects are created and appended to the main object. Then some objects are removed from the model. So, the object model is dynamic structure. It can grow during its life.
In and out of model
When we create an object of some class, that doesn't mean that model is changed. When we append it to the model it becomes part of the model. So, this object can live in and out of model. Typically new object first exists outside the model. It can be filled with other objects and so on. And then to be appended to the model. Someting like a small model appended to the big one.
How model changes
Model can change by replacing an object with onother in some object in the model
Model can change by appending or removing an object in list. When this list resides in the model
Model can change by replacing an object in list
Let's note that instead of objects can be used null(nil) references.
Object model description
A diagram can be used to describe the structure of the object model. It can describe what main object can contain as objects and their types. Also lists of what types are
Why we need object models
If we have object model of something we can manipulate it from outside. Save it to disk and load it. Listen for changes in the model. Clone it. Also when we have it as an unit. We can think about it separately. Without other code arround it. It can be in one dll or assembly. If we import it we will not have to know about anything else except the model. Good code encapsulation! It gives a way of thinking, that helps things get clearer, bigger, less bugs. Faster coding. How it helps get bigger. It comes to a point that we made something that is pretty complex. We feel its very big and hard to handle it.
Rules and mistakes
1. Lists can contain only the items in the list and no fields. Lists and single objects are different things and is better not to mix them. This can confuse the developer. Also lists will be unified and can be handled in common way. More reasons will come to me later :)
I am not sure about the namings yet. May be Object Model will be better name for the description of the structure. So, some ideas here will help me.
Also want to mention that currently the business logic resides in the object model. Object models are part of the business logic layer. That is very good. But I think there is something better here. Busines logic can be removed from the object model. Business logic has to be separated and grouped in reusable components. And then the business logic to be attached to the object model. To listen for the changes. More information about that can be found in Business Component Logic (CBL).
So, thats why we need to have very good notifications for changes in the object model. Here we can use the Observer pattern.Back to main menu