Dynamic association is my new 'magic' programming model that allows objects to be collections of functionalities that are dependent/independent of each other as needed.
Most developers are used to inheritance (is-a) or containment (has-a). There advantages are many and most applications today, use them heavily in their application design. I see association (use-a) as the new way for designing the applications of the future.
Inheritance requires heavy amount of design ahead of time of a project. It requires heavy commitment with calculating what should use containment and what should be inherited. While it does sound great on paper, in real world situations where projects change over time, I have noticed that inheritance unless designed heavily before hand, just does not stand the test of time. Designing complex inheritance relationships ahead of time is not always feasible and over big projects with lots of developers make it a real headache.
My solution of course is 'dynamic association'. Dynamic association allows components to be small, concrete and encapsulated but be part of the same objects. Instead of designing inheritance ahead of time, you dynamically associate (attach/detach) components to objects at run-time. If a window uses hierarchy, just attach the node component to the window object. If the window needs input, just attach the input component to the window object. The association is on the object, not on the component (class).
Its based more on the real world model. A chair is a chair because it has chair abilities. You can sit on a table, so is a table a chair? Of course not. So should you derive the chair from the table or the table from the chair? With dynamic association, you don't need to. If it started as a chair, attach an object to a chair component. If it later on has a table usage, attach a table component to the same object. Its not what an object is, but what it does. Once components are attached to objects, you can cast between the different component instances attached to the same object.
I know its going to take me years to convince developers of this model, I am meanwhile using it heavily in Screens. Its allowing me to write functionality faster than ever, keeping each component to a very small size and all written in native C without macros gives me a lot of clarity which higher level languages lack. C's simplicity in its language features and its code portability allow me to target multiple environments easily.
I hope to continue pushing out components, so developers can see the advantages of dynamic association and start using it in any project. If anyone wants to see what it looks like, check out in the code attached to the post below: http://screensenvironment.blogspot.com/2010/08/first-draft-of-object-storage.html
1 comment:
Not a lot of references out there to objects without inheritance, but here's one: Component Software: Beyond Object-Oriented Programming, by Clemens Szyperski. See my review here
Post a Comment