Re: Java Enums want to be Classes
Posted: Oct 27, 2005 3:15 AM
> > Yes, but, again, it isn't about modeling reality. In
> > opinion, the industry was poorly served by some early
> > voices who touted the idea that OO involved modeling
> > reality and that it was akin to data modeling and AI.
> > It's taking us a long time to get over that.
> I think the industry is poorly served by taking a purist
> view of anything. OO does, in fact, allow us to do
> a better job of modeling reality, and that was a large
> part of its intent. However, the map is not the territory
> and so there will always be some abstraction when (A)
> developing the model and (B) implementing the model.
> Saying that a model must be a perfect mapping is also a
> disservice, especially when it impacts the flexibility of
> the resulting solution.
I'm not a purist about anything, but I'll point out that modelling reality isn't the job. Our job is making maintainable software. The theory is that modelling reality makes the software better somehow, and I don't think that's true.
> What I find is that a system has two facets. First, the
> "modeling reality" part, which tends to drive the initial
> creation of the design, and which ultimately determines
> the usefulness of the result. Second, the pragmatics of
> putting the system together, which inevitably includes
> aspects that are not strongly related to the real world,
> but instead includes aspects to fit things together and to
> facilitate easy change (the latter is not usually based on
> the real world model, but rather on the realities of the
> customer situation).
That's just one way of doing it, however. And it's sad that many people see it as the only way because they start with this "modeling reality" focus that leads to a bunch of traps that they have to sidestep pragmatically. You can design with a behavioral focus from the beginning, and end up with very good designs that may only marginally graze the domain concepts and often that is a very decent thing to do.
A few examples. I once worked on an online auction system where the Bid class was the only one that mentioned the domain. If we used a "modeling reality" approach would have ended up with a substantially different design. The C3 project at Chrysler that spawned XP used Lines, Bins, Stations, and Parts as a classes to do employee payroll, again pretty much orthogonal to a "modeling reality" approach.
In general, I see value in using domain names when possible, but often when I look at the classes I've written with people they are not anything like what you would get from a standard domain model, but that's fine. They make sense in every other engineering aspect. No, I think that there are better alternatives to representational modeling and the focus we have on it is a mistake.