B
bryanbabula
I have a question about overriding i was wondering if anyone could
help me with, or even suggesting a better/different way. I have no
idea if this can even be done or not.
I was wondering if there was anyway to force a class to call a base
class's method that it is overriding? Almost the same way you have to
call a base class's constructor if it has arguments.
(example ** assuming the Person class's constructor has (string
FirstName) as its arguments.
Employee Class will inherit from Person. I know there are different
ways of instantiating classes, but this was just a simple way for me
to explain it.
the Class would be defined as:
public class Employee(string FirstName) : Person : base
(FirstName) ......
in the above example you have to call the : base (FirstName), since
the Person's class has that signature for its constructor.
Basically, I have classes that all have a Validate method. For classes
that inherit from other classes, They have their own Validate method
( which they override the base class's Validate method), but i want to
force them to also call base.Validate(); to force the base class's
validate method to be called as well.
Example, if i have a Person class, my Validate() method might force a
First and LastName, a valid SSN and a valid birthdate. If I have an
Employee class, its Validate method might check for a valid hire date,
a valid department and a valid salary. When the Employee.Validate is
called, i want to force this class to also call the base.Validate
( which is the person class ). This way a developer can't forget to
call the base.Validate and make a mistake.
Does anyone know how to do this, or suggest a better / different way
of making this happen.
Thanks
Bryan
help me with, or even suggesting a better/different way. I have no
idea if this can even be done or not.
I was wondering if there was anyway to force a class to call a base
class's method that it is overriding? Almost the same way you have to
call a base class's constructor if it has arguments.
(example ** assuming the Person class's constructor has (string
FirstName) as its arguments.
Employee Class will inherit from Person. I know there are different
ways of instantiating classes, but this was just a simple way for me
to explain it.
the Class would be defined as:
public class Employee(string FirstName) : Person : base
(FirstName) ......
in the above example you have to call the : base (FirstName), since
the Person's class has that signature for its constructor.
Basically, I have classes that all have a Validate method. For classes
that inherit from other classes, They have their own Validate method
( which they override the base class's Validate method), but i want to
force them to also call base.Validate(); to force the base class's
validate method to be called as well.
Example, if i have a Person class, my Validate() method might force a
First and LastName, a valid SSN and a valid birthdate. If I have an
Employee class, its Validate method might check for a valid hire date,
a valid department and a valid salary. When the Employee.Validate is
called, i want to force this class to also call the base.Validate
( which is the person class ). This way a developer can't forget to
call the base.Validate and make a mistake.
Does anyone know how to do this, or suggest a better / different way
of making this happen.
Thanks
Bryan