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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Valid use of Inheritance?? 1

Status
Not open for further replies.

ChrisPlatt

Programmer
Feb 20, 2005
11
GB
I'm going round in circles trying to get my head around the usage of Inheritance within a system I am trying to design. I would REALLY appreciate any experienced advice on the following scenario:

I have an abstract base class named CustomerServiceType which has a single method named IsAvailable. I have two classes deriving from the base which will implement the IsAvailable method and return a true/false. The issue I have is that each of the subclasses require a parameter of a different type in order to evaluate the IsAvailble method.

The only was I can think of to deal with this situation is to pass in the parameter via the constructor? - Is this bad practice or bad design?

Please help!....
 
Chris

Are you saying that once instantiated, the concrete classes are able to respond to IsAvailable(), but require constructors with radically different signatures? Given that there is only a single method, you don't seem to be getting much added value from your abstract superclass. Maybe you might be better off with an interface IAvailable, and have both the classes implement it?
 
Making an interface for a property like e.g. availablity, i don't think this is a good choice. IAvailable is not an interface expressing a general structural property like ISerializable, IComparable, or IHashable, etc. So it might lead to misunderstanding.

ChrisPlatt, If you think CustomerServiceType or CustomerService is an important concept in the domain of your application, you should keep it. Even if for the moment it has only one deferred function 'isAvailable'. The class might get enriched later.
Passing the peculiar parameters needed by the different redefinitions of `isAvailable' to the constructors, it's a valid solution. Constructors are made for that.

--
Globos
 
I don't have an objection to the passing of a parameter on the constructor (as globos rightly says, that's what they are for). But I am concerned that in order to get the benefit from the abstraction of the superclass, the client shouldn't need to be aware of the subclass. If the client needs to know the explicit subclass in order to intantiate it, then where's the benefit?
 
Thanks for the advice.

The CustomerServiceType class is VERY important within the system but I haven't so far been able to identify any other useful details about the respective CustomerServiceTypes other than the business rules behind whether they are available.

I'll give a few more details behind the system to hopefully clarify things for you:

Top level base class: CustomerServiceType
3 Classes that derivie from top level base class: Renewal, Claim, ChangeOfAddress

The Renewal subclass has the following subclasses deriving from it: CarRenewal, HouseRenewal

The ChangeOfAddress subclass has no subclasses

The issue I have arises from the fact that the IsAvailable method implemented in each subclass that derives from Renewal needs to operate on a Policy class but the ChangeOfAddress IsAvailable method needs to operate on a Client class.

Hope this helps...
 
Accepting for now that they are very important, what are they supposed to do? If the only thing you can do to them is ask them if they are available, in what processing context do you need ask them this question? Who creates them, and who uses them? What happens next?

Also, does an address change to a client ripple through to all/some/none of the policies they hold?
 
The resultant answer to the IsAvailable method will return a true/false value which will determine whether the option to fulfil the CustomerServiceType against the policy/client. For example, whether a button is enabled or not.

There are other classes I have identified which relate to the CustomerServiceType class but only in a 'has a' relationship (i.e. the CustomerServiceRequest class, which contains details about a submitted CustomerServiceType, 'has a' CustomerServiceType).

An address change does not ripple through all policies.
 
Just checking my understanding: You want to get a list of available services depending on whether you are dealing with a Client or a Policy, to set buttons in the UI. You create one of each type of service, passing in the object on the constructor. Then you ask each one in turn whether or not it is available, enabling buttons as you go. When one of them is selected, you create a CustomerServiceRequest passing in the selected CustomerServiceType on the constructor.

It might be simpler to abstract the creation behaviour into a Factory that returns a collection of available CustomerServiceType objects. Then you don't need the IsAvailable() method, as only available services get returned. This slims down the UI code, reduces coupling, and makes the factory reusable from multiple forms.

I guess that the CustomerServiceType object has a reference to the Client or Policy it relates to, so that when it gets passed to the CustomerServiceRequest object constructor it has everything it needs to start work.
 
I am having an interesting time deciphering the problem. Steve, seems like you're thinking that he wants to retrieve a list of avaliable policies/clients and configure his ui based on the list.

But when reading his postsm, I get the idea that Chris wants to configure the UI for a particular entity selected [EX: Enabling some button only if that entity is avaliable]. So it looks like we are talking of only a single randomly selected entity at runtime..

Is this right?
 
The exact scenario that I am working with is as follows:

I am building up the content for dynamic web page. In order to do this I am looping through an array of Policy classes and displaying policy related information. One item of information I need to display for each Policy in the array is whether or not a CustomerServiceType is available for that policy. If it is available then I will provide a hyperlink to the related Customer Service.

However, the added complication comes when I identified the that I have CustomerServiceTypes that are applicable to either a Policy class or a Client class - i.e. a Policy can perform a Renewal CustomerServiceType and a Client can perform a ChangeAddress CustomerServiceType.

Hope this helps Edward...
 
ok, so far so good. I am trying to understand the common language in your domain. So, what exactly is a "CustomerServiceType"? Especially when used in the context:

>>
"i.e. a Policy can perform a Renewal CustomerServiceType and a Client can perform a ChangeAddress CustomerServiceType."
>>


What is the semantics behind a Policy or Client performing a Customer Service Type? This is what I don't understand.

If i was to re-edit your statement to:
"a Policy can perform a Renewal". It sounds more logical.

Sorry, can you clarify your domain even further?
 
A CustomerServiceType is a service that is offered by the website relating to a core business entity (i.e. Policy or Client). Examples of these are a Renewal or Change of Address.

My view of it is that a Policy or Client can have a CustomerServiceType performed on it.

For example a Renewal can be performed on a Policy.

Your statement <<"a Policy can perform a Renewal">> does not sound sematically correct to me as a Policy cannot renew itself. The real-world implementation of a Renewal would include the resetting of Policy inception and renewal dates and taking of payments etc.

However, the actual implementation of a Renewal is out of scope in my project. It is just the availability of the Customer Service that I am concerned with (i.e. the business rules behind whether a renewal is available are whether a Policy renewal date is inside 21 days from now).

Thanks for your help...

Chris
 
OK, after reading and rereading your posts I finally seem your domain. First I will confirm your domain, let me know if it's correct. Second I will let you know what you might be doing wrong:

[btw, let's called it ServiceType instead of CustomerServiceTypes, you'll see why shortly]


Domain:
Various Service types are avaliable, Renewals, ChangeOfAddresses and Claims, to name a few. There are also Customers such as Clients and Policies to name a few. The problem is, you need to know if a certain customer is capable of having a service change (renewabl or Claims change).
?????


I think you have misused inheritance here. This is why. Let's think conceptually at a higher level for just one minute.

You are dealing with Services and Customers. 2 different entities. With that said, let's apply the "encapsulate what varies" principal to produce an inheritance chain for Services and then Customers:


[Service] - BaseClass
[RenewalService] - Derived
[ClaimService] - Derived
[ChangeOfAddress] - Derived


Now let's produce a an inheritance tree for your various Customers:

[Customer] - BaseClass
[PolicyCustomer] - Derived
[ClientCustomer] - Derived


As you can see we have customers and services. Let's relate them now. We can relate a customer to a Service via has-a relationship. We can do this at instantion time via the Customer Constructor:


Customer aCustomer = new PloicyCustomer(new RenewalService());

We have ourselves a Customer now, related to a service.
Do we care what kind of customer it is? No, do we care what kind of service they have? No. All of this is abstracted because we are talking about abstract types not detailed types.


We can setup an abstract property on the Customer Base called:

IsServiceAvaliable();


then in your code, to find out if a Customer, such as a PolicyCustomer is avaliable for a renewal you can simply ask it:


bool isAvaliable = aCustomer.IsServiceAvaliable();


does this make sense?

- Edward J.S.
 
OK, now I'm really confused. Policies aren't Clients, and vice versa. I'm assuming Client = Customer (<<Party>>), and has a role or roles linking it to a n Policy (<<thing>>) objects (either as holder, beneficiary, etc.).

On your dynamic web page, you list out Clients and their Policies. For each, you want to know if (any/which) Services are available.[ol][li]Under what circumstances would an AddressChange not be available for a Client (bearing in mind that you can't stop them moving house, and you will need an up-to-date address if they do). If something is always true, why do you need another object to tell you that?[/li][li]What happens if they have more than one available service? If a policy can be renewed, then surely they can make a claim too?[/li][/ol]

Sorry there are more questions than answers!
 
Steve,
Look at the recent post from chris, he states:
"A CustomerServiceType is a service that is offered by the website relating to a core business entity (i.e. Policy or Client). Examples of these are a Renewal or Change of Address."


"A CustomerServiceType is a service"
"relating to a core business entity (i.e. Policy or Client)."


Also, reading all his posts, he's grouping policy and client together, which i am inferring is related via some hierarchy.


Jay

 
OK, so you are Jay, not Ed. My bad[blush]

Re-reading Chris's post
The exact scenario that I am working with is as follows: ...
it says he is looping through a list of policies to make a dynamic web page. So it seems like we are only dealing with policies here, but the problem is that other things (Clients) may also have CustomerServiceTypes too.

We could get over that with two constructors for CustomerServiceType, one that takes a Client, and one that takes a Policy. The dynamic web page is only interested in policies, so it is only interested in the Policy-type constructor.

The issue I have is that we don't want to instantiate six different CustomerServiceType objects for each Policy, just so that we can call IsAvailable() on each one to see if it is allowed. This means that the UI has to know about all possible services, and has to change if they add a new service. Why not return a list of available services for each policy/client, and use them in a Command pattern?

Also, if a Policy has more than one service available, will each one be a separate link on the dynamic form?
 
Each one will need a seperate link on the dynamic page.

I will need to check for the availability of several services for a single Policy (i.e.Renewal, Claim etc.).

Certain services will always be available (i.e. ChangeOfAddress) therefore minimal business logic behind those.

Thanks for all your help!

Chris
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top