INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Factory Question

Factory Question

(OP)
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?

RE: Factory Question

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: Database Connection Management
FAQ732-7259: Keeping the UI responsive

RE: Factory Question

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.

RE: Factory Question

(OP)
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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close