I am trying to write a small application using Scala-Graph. It is a nifty package alright, but while modelling the application's entities, I am facing a question.
Let us say that we are modelling employees in an organisation. An Employee belongs to only one Department but can belong to two or more SocialClub. If we consider the Organisation as a Graph, then
var organisation = Graph[Employee,GroupsInOffice]()
// .....
val e1 = Employee (1, "Nirmalya")
val d1 = Department("Finance")
val d2 = Department("Sales"
val club1 = Club("Beer Drinkers")
val club2 = Club("Horse Riders")
// ....
So, the following should be allowed:
organisation = organisation(e1 ~ club1,e1 ~ club2)
But, the following should not be allowed:
organisation = organisation(e1 ~ d1,e1 ~ d2)
My question is what is the pattern one adopts to ensure the prevention. Should it be a constraint that is defined on the Graph itself (organisation) or should it be a application-level check that counts the the number of times e1 is used in setting the relationship (~)? Is there any other particular approach that one takes in a situation like this?
Aucun commentaire:
Enregistrer un commentaire