16. Accountability and Affiliation
Affiliation
An organizational model of an enterprise such as a business, government, or university must take into account two things:
The problem with this model is that both the rules and types of organizations change from time to time and from enterprise to enterprise. It's also not clear how programmers should enforce the constraint attached to the affiliation association.
We can improve the model by modeling organizational types by objects rather than classes:
Now Division, Department, and Office are just sample instances of the OrgType class. If the types of organizational units change, we only need to delete some old OrgType objects and create some new ones.
Of course OrgType objects can also be factories that create properly typed organizations as their products:
A rule is a general constraint, such as:
Thus the facts:
Modeling rules (i.e., fact types) as classes will produce a massive and difficult to maintain hierarchy of classes. A better approach is to model rules as objects:
A Reusable Organization Model
If we take this approach in our organizational model, then we notice that affiliation facts are simply the instances of the affiliation association. Since a fact must store its rule/type, we'll need to represent links between parent and subsidiary organizations as link objects, instances of an association class named Affiliation. An interesting observation is that in this case instances of our rule class-- AffilType-- are link objects that link OrgType instances, making AffilType an association class, too:
Example
Organizations are now modeled by object diagrams rather than class diagrams. For example, at most universities:
Fact: The Math and Physics departments are subsidiaries of the College of Science.
A C++ Implementation
class OrgType
{
private:
string name;
AffiliationType*
parent;
list<AffiliationType*>
subsidiaries;
public:
OrgType(string
nm = ""):name(nm) {} //default constructor
//factory method:
Organization* makeOrganization(string
temp);
//getters:
string getName()
const {return name;}
//utility functions:
void setParent(AffiliationType*
a) { parent = a; }
void addSubsidiary(AffiliationType*
a) { subsidiaries.push_back(a); }
};
class Affiliation
{
private:
friend class AffiliationType;
AffiliationType*
type;
Organization *parent,
*subsidiary;
// default constructor:
Affiliation(Organization*
p = 0, Organization* s = 0)
:parent(p), subsidiary(s)
{
if (p) p->addSubsidiary(this);
if (s) s->setParent(this);
}
//copy constructor:
Affiliation(const
Affiliation& a) {}
public:
//getters:
AffiliationType*
getType() {return type;}
Organization* getParent()
{return parent;}
Organization* getSubsidiary()
{return subsidiary;}
};
class AffiliationType
{
private:
OrgType *parent,
*subsidiary;
public:
AffiliationType(OrgType*
p = 0, OrgType* s = 0)
:parent(p), subsidiary(s)
{
if (p) p->addSubsidiary(this);
if (s) s->addParent(this);
}
//factory method:
Affiliation* makeAffiliation(Organization*
p, Organization* s)
{
// only creates valid affiliations
}
//getters:
OrgType* getParent()
{return parent;}
OrgType* getSubsidiary()
{return subsidiary;}
};
// simple solution:
public class Organization {
private OrgType type;
public OrgType getType()
{ return type; }
Organization(OrgType t)
{ type = t; }
// etc.
}
public class OrgType {
private String name;
public Organization makeOrganization()
{
return new Organization(this);
}
// etc.
}
// complex solution:
public class OrgType {
private AffilType parent;
private Set subsidiaries;
public class Organization
{
private AffilType.Affiliation
parent;
private Set subsidiaries;
public OrgType getType()
{ return OrgType.this; }
// pulic default constructor
ok
// etc.
}
public Organization makeOrganization()
{
return new Organization();
}
// etc.
public static void main(String[]
args) {
OrgType league, conference,
division, team;
OrgType.Organization
afc = conference.makeOrganization();
OrgType.Organization
nfc = conference.makeOrganization();
OrgType.Organization
nfl = league.makeOrganization();
// equivalently:
// OrgType.Organization
afc = conference.new Organization();
AffilType rule1 = new
AffilType(league, conference);
// "type" checking done
inside makeAffiliation():
AffilType.Affiliation
fact1 = rule1.makeAffiliation(nfl, afc);
// etc.
}
}
Accountability
Accountability structures model the relationships between roles. Basically, every role has commissioner roles and responsible roles. For example, a doctor is commissioned by a patient. Nurses are a doctor's responsibles because they are commissioned by doctors.
This is similar to the parent-subsidiary relationship between organizations, but commissioners and responsibles can be any type of role. For example, the CEO of a company is responsible to the company's board of directors, the vice president of the marketing division is responsible to the CEO, the marketing division is responsible to its vice president. Clearly there are many links between commissioners and responsibles and the rules between them can be complicated and they can change frequently.
To cope with this volatility, we can use a version of our reusable affiliation model:
Example
Accountability is called chain of command in military organizations. Here's a bit of the the Star Fleet chain of command:
Problems
1. The 97th Infantry Division of the U.S. Army was active in Europe near the end of World War II. The history and organization of this division is documented on the web at:
2. Translate your model into C++ or Java.
3. The accountability structure of San Jose State University is documented on the web at:
4. Translate your model into C++ or Java
5. The National Football League (NFL) is divided into the National Football Conference (NFC) and the American Football Conference (AFC). Each conference is divided into Western, Central, and Eastern Divisions. Each division currently consists of five teams. Using the organization model developed in class, draw an object diagram that shows the following teams as well as their conferences, divisions, and league. (You can find out which divisions these teams belong to at Yahoo or at www.nfl.com). Translate your diagram into a C++ program.