Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Using classes of different types
Message
De
26/08/2005 11:13:37
 
 
À
25/08/2005 19:25:35
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01044144
Message ID:
01044325
Vues:
13
In each type of worker class you instantiate the different class you need, such as:
class worker_emp

public worker_emp
{
    calcpay = new calc_emp_pay
}


class worker_manager

public worker_manager
{
   calcpay = new calc_manager_pay
} 
Calcpay would have to have to be based on the same interface. Now in your main program, whenever you are processing worker classes, you can just call calcpay.calc_salary and the proper class will be referenced.

PF


>The worker class will always come from the same base class, hence each will have the same public interface.
>
>>This is a design pattern issue. According to what I've read, you should create an interface to describe the classes the worker could be part of. Maintenance is far easier if the class always has the same signiture. So there is nothing you would need to change in the calling program if you add another class the worker can be part of.
>>
>>PF
>>
>>>In VFP, if I needed to instaniate classes of different types I would do something like this:
>>>
>>>define class Myclass as session
>>>  worker = null
>>>
>>>  proc init(cworker)
>>>     do case
>>>       case cworker = "A"
>>>         this.worker = createobject("ClassA")
>>>       case cworker = "B"
>>>         this.worker = createobject("ClassB")
>>>      endcase
>>>   endproc
>>>enddefine
>>>
>>>
>>>My problem is that because C# is strongly typed, I don't know how to make worker be an instance of one of several different classes. Any suggestions?

(On an infant's shirt): Already smarter than Bush
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform