Quote:Original post by jpetrie
I think Antheus was getting at the same thing I am: we need some additional contextual information, some information about what these useless letters represent. This is an OO design problem, and to deal with it effectively you need to speak in the vocabulary of the objects.
Ok then if specifics are needed. The most recent example of this problem that I ran into was for the items in a shop. A is the base class for the item, and B-H are various different kinds of items. A has many different virtual functions that B-H all implement. The function func() from the example is:
virtual int getprice( Person* owner );
Each item type uses the owner and its own data to determine its price.
The new class that I'm trying to add(I) is an item type where the price depends on the time of day or the day of the week. In order to do that, the getprice() function needs to have access to that information.
Another example of a class(J) would be a type of item where I want some aspect of the buyer to influence the price, so getprice() would need access to that.
With those two new classes, my getprice() function either becomes:
virtual int getprice( Person* owner, Person* buyer, int dayofweek );
and all the other classes just ignore buyer and dayofweek, or I put the special cases at the point where I call getprice().
Obviously, I don't really like either of those options. If there's no other way to restructure things or set this scenario up I can accept that. I just hope there's some better way.
Thanks again,
Simon