Or does the fact that there are significant differences in the database tables to which we are mapping make it all right to have two separate but very similar sets of classes?
<a href="http://www-306.ibm.com/software/rational/bios/ambler.html" target="_blank" rel="nofollow">Scott W. Ambler</a><br />Practice Leader Agile Development, IBM Rational<br /> <br />Now available: <a href="http://www.ambysoft.com/books/refactoringDatabases.html" target="_blank" rel="nofollow">Refactoring Databases: Evolutionary Database Design</a>
SCJP, SCWCD
Originally posted by Mr. C Lamont Gilbert:
Is this a loaded question? I never heard of DRY before but it has nothing to do with object oriented design IMHO. The answer is NO![]()
I would absolutely not share base classes. I would absolutely duplicate the classes. Ctrl-c, Ctrl-v. Of course thats just my opinion and I dont run a big software house.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
<a href="http://www-306.ibm.com/software/rational/bios/ambler.html" target="_blank" rel="nofollow">Scott W. Ambler</a><br />Practice Leader Agile Development, IBM Rational<br /> <br />Now available: <a href="http://www.ambysoft.com/books/refactoringDatabases.html" target="_blank" rel="nofollow">Refactoring Databases: Evolutionary Database Design</a>
it didn't make sense to me to make dtoV1 and dtoV2 be subclasses of some dtoBaseClass just to eliminate duplication of the getter/setter code for attributes that were common to both versions.
Originally posted by Ilja Preuss:
I probably wouldn't use simple inheritance, if only because it sounds too brittle to me. I definitely wouldn't rape and paste, either.
It's hard to say what I'd do without knowing much more specifics about what the classes do and where they need to differ, but I'd probably think about using Strategies, meta data or perhaps even code generation.
For example, how much of the difference between the classes behaviour could be inferred from the schemas themselfes?
Originally posted by Mr. C Lamont Gilbert:
I think you should look at the situation differently. Its not variance he is trying to abstract away, but versionance. I believe trying to use a class heirachy to encapsulate change due to versioning is a big mistake. Thats what CVS is for. Start a new branch, which is basically ctrl-c ctrl-v.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Junilu Lacar:
We are, in essence, extracting data from the third-party database(s) and persisting it to a database that we do have control over. We will have only one set of classes to model our side of the fence and these are the classes that we use to perform most of the business logic.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Ilja Preuss:
Branches are good if you need to support old versions of your software for some time. They are horrible, in my experience, for maintaining different versions of the software that need to be evolved concurrently, *especially* if you have to use CVS. A combination of metadata and polymorphism is the right choice in that case.
Originally posted by Ilja Preuss:
you could write the mapping in a more declarative style and have your java program interprete and execute it.
Originally posted by Junilu Lacar:
We are using Hibernate to do the O-R mapping.
The vendor's database uses composite keys, which we decided we did not want to do in our database. This made it necessary for us to write code to "convert" the objects mapped to the vendor's database into the objects that we had mapped to our database. The conversions were not necessarily one-to-one and each version of the vendor's database requires slightly different conversions.
Mhh, could you write reusable converter classes, perhaps combining different rules using the composite pattern or something like that?
I did manage to get the team to go along with my preference of not creating a base class but I don't think they are totally convinced that it was not a good idea to create one so that they could eliminate duplication. I posted the question because I was hoping to add to my seemingly unconvincing answer that "it will just make the code more brittle and I don't think it's worth creating a hierarchy that doesn't provide any other benefits or use."
I can understand your feeling that it's too brittle. On the other hand, I'd really try to remove the duplication in *some* way. If it isn't clear which way, I might well start with simple inheritance, and refactor away from it when I learn more about the needs of the system...
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Mr. C Lamont Gilbert:
The way the current base class will be created is to look at what is similar between the two versions and put that in the base class. When a third version comes, it could have less in common.
Should we;
remove that part that is not common across all 3 versions from the base class and modify the two existing versions. start a new base class for our new version?
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Ilja Preuss:
extract the differences into Strategies handle the differences using the Interpreter pattern use a more data driven approach something I wouldn't think of before actually being confronted with the situation, having gathered a lot of feedback from trying different things and discussing them with my coworkers any combination of the above
I would work hard on removing the duplication, and I would never (mis)use CVS branching for this. Seriously.
Originally posted by Mr. C Lamont Gilbert:
To be honest, the OO encapsulation of variation did its job when they choose Hibernate. They have isolated the business side of their application from the changes in the datastore.
Your OO design approach to solving this versioning issue is an attempt to isolate their DAO layer from changes in the datastore.
The path I choose provides easier protection from future versions. The path you choose provides easier maintainance of current versions.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Ilja Preuss:
The more we work on having the code express and handle the current differences in versions smoothly, the more flexible it will become with time to also handle differences in future versions smoothly. It will become less and less effort to support another version.
Originally posted by Ilja Preuss:
they'd just need to change the hibernate mapping, or so it seems to me.
Originally posted by Mr. C Lamont Gilbert:
A design deals with a specific type of change. If another type of change comes along, it requires a different or modified design.
Your not supposed to redesign your architecture when a change comes, but part of your implementation.
Furthermore, you will put a lot of work into designing an architecture to deal with something that may or may not happen. Its a kind of defensive architecture.
However, its the DRY that I strongly disagree with. The idea of modifying the base class as a way of abstracting out the change is a poor choice.
In this particular case, that would be compounding the problem since the two versions would be strongly tied to this base class, and a 3rd version would force refactoring of everything.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Ilja Preuss:
What do you mean by "architecture" here, and why am I not supposed to "redesign" it?
Originally posted by Mr. C Lamont Gilbert:
"Architecture" is the design of your program. For instance, if you adopt the strategy pattern, adding a new strategy is not a change of architecture. However, switching from strategy to chain of responsibility is.
When you use a tool like hibernate or JDO you have already abstracted your business layer away from your data layer. Or you were supposed to.
I can't begin to imagine how one would maintain a single class heirachy supporting different schemas using ORM.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Ilja Preuss:
Ok. I do that switching all the time. What's wrong with it?
Originally posted by Ilja Preuss:
Well, I understood Junilu to say that hibernate didn't fully abstract away from the data layer for his team.
Originally posted by Mr. C Lamont Gilbert:
Nothing is wrong with it. However, the objective of software design is to prevent this. This happens when it happens, but I feel its undesirable and does not scale well.
You need a layer dedicated to your ORM. I think this layer should change with the ORM and not try to be abstract from it.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Don't get me started about those stupid light bulbs. |