Model the real world

From CSSEMediaWiki
Revision as of 03:11, 25 November 2010 by WikiSysop (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Model the real world whenever possible. (This heuristic is often violated for reasons of system intelligence distribution, avoidance of god classes, and the keeping of related data and behavior in one place). --Riel's Heuristic 3.6, Arthur Riel 1996

Object Oriented programming is all about modelling the real world. We do this because in theory it is easier to think about how something works if it exists in the real world. For example, a trivial Car class would be easy to implement, as most people know what a car is made up of, at a high level sense. Modeling real world objects is considered easier than modeling complex, artificial algorithms and control processes that only exist in the domain of the program they are being developed for.

OO also gives programmers a way to decompose a problem into smaller components that "make sense". Of course, this all relies on being able to make good OO models (ie choosing good classes). The main guideline is to model what actually exists in the real world. For example, Car and Road may be good OO classes, but VehicleAndRoadController probably isn't very good. A class name that has no meaning outside of the computer program may be a sign you are not modeling the real world. Of course, exceptions will occur in certain domains, and it is not often as easy as just "modeling the real world".

See also

Domain model pattern

Personal tools