I am currently working on problem with a chicken or egg first situation. Basically, I am designing a solution which goes like this:
World
is a collection of countries;- Each
Country
has a name, flag and president (all are strings); - There will be relations between countries, like country A is friend or supporter of country B. So there will be many countries which are either friends of other countries or the leader countries;
- There will be some conditions for whether a country is friend or not, based on the number of trades between the countries. If country X exports more to say countries P,Q,R,S then X is the leader country and P,Q,R,S are its friends, and so on for other countries.
At any point of time I may need to handle the request like: who is the ultimate leader country (which has max supporters or friends etc),
or who are supporters of the ultimate leader country, or who are supporters of any given leader country, etc. The trick here is the basic properties of friends or leaders are same (like every Country
has name, flag, president)
I want a good skeleton structure to address the basic service requirements of this problem statement. But I need a design able to handle any future extensions, such as successors, descendants, duration of ruling, family of presidents, etc.
I am confused in deciding which approach to follow: do I need to make (Approach 1) or should I define (Approach 2).
Approach 1: Country
is part of World
class World
{
class country *country_list // not taking array , so that i need not to limit the list
};
Approach 2: Country
defined first and World
inherits from it
This looks odd, because Country
is a small entity and World
is big entity. And, then what would be the contents of world, but again its a list of countries.
class World : Inherit class country
{
// not sure what should be the content here
// can getcounty();
// add_country_to_world();
//
};
//not sure wether to make this abstract or normal.
//no duplicates countries are allowed.
class country
{
string countryname;
string flag;
string president;
};
Then I would like to make a mapper which contains a key (made of country name) and values are its details, like country is friend or leader, no of friends, so that i can directly check who is ultimate leader.
ILandMass
or something. That would make a lot more sense.