Help with OO Problem
I've studied OO at University in the shape of Eiffel, I've programmed OO somewhat lightly in Java and developed OO in CFCs but there are some classes of problem I just don't get. If anyone reading this could offer insight from their own experience that would be great! I'll offer problem 1 for now and dependent on the response I might hit you up for problem 2.
"is related to"
I've called this "is related to" because I'm talking about the modelling of relationships between classes. This comes in the context of how to use objects in a Content Management System.
For example, lets say I have a website with an about us section and in that section, an programmer list with a list of the key skills of each programmer. There is also a "key skills list" which has a list of programmers who are in posession of the skill. Programmers own skills but they aren't necessarily composed of those skills e.g. "has a" and this isn't inheritance since programmers aren't a type of ColdFusion.
So, to make it real, under the list of programmers I have Ben Forta, DHH, Adam Howitt, Sean Corfield and Cameron Childress. If you view the detail for each programmer you will see that all but DHH have ColdFusion experience. All have MySQL experience and lastly Adam and DHH have dabbled in Rails. If I navigate to the ColdFusion page I see a list: Adam, Ben, Cameron, Sean with a brief snippet of the full bio under each.
On the ColdFusion page I would fetch the ColdFusion object and dutifully write out each attribute before getting the related programmers:
<p>#skillObj.getBody()#</p>
<h2>Related Programmers</h2>
<ul>
<cfset stProgrammers=skillObj.getProgrammers()>
<cfloop collection="#stProgrammers#" item="programmer">
<cfset currentProgrammer=stProgrammers[programmer]>
<li>#currentProgrammer.getFirstName# #currentProgrammer.getLastName#<br/>
<p>#currentProgrammer.getShortBio()#</p></li>
</cfloop>
</ul>
My question is how do you implement getProgrammers and what do the classes look like? My initial thought is that there is a Programmer class and a Skill class. Now for the chicken and the egg: does a programmer has a struct of skills (order isn't important) or does the skill have a struct of programmers (again, order not important). Or both? What do I store? The struct of class instances (programmer objects) or the struct of ids? If I use a struct of objects, the call getProgrammers has all the information it needs to print this page.
If I store the ids of the objects then I increase cohesiveness by requiring the method to call a function to instantiate the skill class for each id. Storing the ids creates a new issue - I have to load each skill one by one, making multiple database calls for each page request instead of a single database call to load all related skills. In the current system, I load all skilll attributes with one query, all related programmers with another then display them to the screen.
The biggest issue I am having trouble understanding is what gets stored in memory. We don't really have a Programmer or a Skills page, but model the employee structure and skills profiles of clients in the service industry. Some clients have over a thousand employees with experience or skills selected from a list of over a hundred. Adding up the potential number of objects, some clients may have over 5,000 content objects which may be called by any number of pages at a given time. The current procedural approach works but we're trying to see if there is a better OO design to fit the purpose.