I have a set of objects that represent different levels in a hierarchical organizational structure, in this instance a statewide school system.
At the bottom of the hierarchy is the school. It is administered by a town, which is administered by a disctrict, and so forth, like this:
State
Region
County
District
Town
School
Now if this were all there were to it, it would be easy. My School object would have an "administeredBy" property that pointed to a Town, and the Town would have an administeredBy property that pointed to a District. Similarly, a State would have a "administers" property that was a List of Regions, etc.
The problem is that steps can be skipped. For example, some schools are regionally administered. So the "administeredBy" property has to allow a Town, District, etc.
Obviously, the solution is an AdministrativeUnit class (interface, trait) from which all the above classes (except School) extend. (And an AdministeredUnit for everything below State.)
This allows me to have a School administeredBy Region and a Region that administers Schools.
The problem is that it also allows me to have a Region administeredBy a Town and a District that administers Counties.
Is this clear?
So is there any way for me to set this up in OOP to prevent the above problem? If it helps, I am working in Scala (or Java).
At the bottom of the hierarchy is the school. It is administered by a town, which is administered by a disctrict, and so forth, like this:
State
Region
County
District
Town
School
Now if this were all there were to it, it would be easy. My School object would have an "administeredBy" property that pointed to a Town, and the Town would have an administeredBy property that pointed to a District. Similarly, a State would have a "administers" property that was a List of Regions, etc.
The problem is that steps can be skipped. For example, some schools are regionally administered. So the "administeredBy" property has to allow a Town, District, etc.
Obviously, the solution is an AdministrativeUnit class (interface, trait) from which all the above classes (except School) extend. (And an AdministeredUnit for everything below State.)
This allows me to have a School administeredBy Region and a Region that administers Schools.
The problem is that it also allows me to have a Region administeredBy a Town and a District that administers Counties.
Is this clear?
So is there any way for me to set this up in OOP to prevent the above problem? If it helps, I am working in Scala (or Java).