Last post Dec 21, 2009 11:53 AM by atconway
Dec 19, 2009 10:12 AM|jamieslucky7|LINK
I have 2 business classes, user & salutation and 2 DAL classes of the same name.
The business classes both have properties of the data class E.g.
Public Property Data() As Data.Salutation
Set(ByVal value As Data.Salutation)
_Data = value
If value Is Nothing Then
_Data = New Data.Salutation
To access some data, you would do Business.Salutation.Data.SalutationID
Both busines classes inherit from BaseClass which contains all my database access methods.
Is there a way that I can access the Data property of the inheriting classes from the BaseClass?
I assume I will need to use reflection as the property types will always be different.
Dec 19, 2009 04:56 PM|rilov|LINK
When you design the class you should know the relation ship between them
hope this article will help you to understand the classes and the relation between them
Dec 21, 2009 11:53 AM|atconway|LINK
So basically you are asking how to access a child's class properties from the parent, correct?
If this is true, I would recommend not designing your classes in such a manner regardless. Accessing child class properties from the parent (if even possible) is not a good idea, because the parent class is not really a 'parent' class anymore. It can not
live on its own and is now dependent on its children.
You do have a couple of options to redesign to make more sense of the inheritance chain. 1st, you could bump up those needed properties from the child class to the parent class and be done; at that point the parent classes would be able to access the properties
you need it to. If it does not make sense to move those properties up a level because they are too specific to the child classes, and it may be a bit sloppy, then you may have your inheritance chain upside down or incorrect to begin with.
If the database method calls are specific to the class, then the child class could really become the parent, and the db calls could be come the child class. If the db calls are more generic and should be available to all classes, then consider breaking
them off into there own separate class that is not in the inheritance chain, but accessed through instantiation when needed. Then you could design the classes and their inheritance more appropriately, and have the DAL methods as part of their own class accessible
by any Business Logic class you need them for.