Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Factory Question 1

Status
Not open for further replies.

cisberner

Programmer
Apr 12, 2011
2
0
0
AW
Hi,
I have a factory method in a class "Country" which returns the appropriate object "Taxtable" depending on the year.

Another class is the Company, and the company can be in one country, therefore the Country object can be instantiated by the Company class.

In my code I instantiate the Country class like this, getting it from the company object which is always available (a singleton):

Country = Company.GetCountry()
Taxtable = Country.GetTaxtable(2011)

Now to make it easier to access, does it make sense to create another method in Company which returns the taxtable directly, so I don't need to go through the step to get the country first?

Taxtable = Company.GetTaxtable(2011)

And the Company class GetTaxtable method uses then the factory method in Country to return the taxtable to the caller.

Does this make sense, or does it break any rules of OOD?
 
who has the responsibility of determining tax? in this model it's country. just because company is associated with a country doesn't mean company is also responsible for tax.

I think your original design makes more sense. the addition of a facade method on Company doesn't add value.

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
Let me ask you this: Suppose you inherit from company a class Corporation that has a collection of countries and that has to determine taxes in multiple countries. What happens to the TaxTable property then? IMHO, you can't determine the TaxTable until you know which country you are "in", so how can you get a TaxTable without having country set? Now you have to rewite the entire Taxtable property to take into account the fact you can have more than one country. By having to go through the Country object to get the TaxTable, you enforce ownership, simplify development later and make debugging down the road much easier.
 
@Prattaratt: maybe, but that wasn't the context in with the problem was expressed.

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
To clarify:

The idea of Taxtable = Company.GetTaxtable(2011) was that Company uses the Country to get the taxtable. The code in Company.GetTaxtable() looks like this:

Country = this.GetCountry()
RETURN Country.GetTaxtable(2011)

So the Company is not really responsible for determining the taxtable, but it uses the country to get the taxtable and returns it to the caller.

The reason for this would be to have a shorter way to get the taxtable object.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top