views:

211

answers:

1

Hi there, I have a clue about Object Oriented Programming:

I need to have a parent class HandlerException which needs to define the sign of three methods (MethodA, MethodB, MethodC).

Then, I have a child class BusinessHandler which inherits from HandlerException and defines ONLY the MethodA of its parent class.

Then, I have a child class DataHandler which inherits from HandlerException and defines ONLY MethodC of its parent class.

Then, I have a class named CustomerDAO which inherits from DataHandler and consumes the MethodC written on its parent class. (consumes it like: DataHandler.MethodC).

As you can see, its a typical object oriented programming problem; I need to have some static methods (MethodC) to access it directly without any instance of the class. The parent class HandlerException could be abstract? and its 3 methods (A, B and C) could be ???? (that's my question, how is the RIGHT way to write this parent class: abstract with abstract members, or virtual, or maybe an interface?)

I hope you got the idea of my question and that I made myself clear. Thanks in advance.

I forgot: I'm using C#, and to mention: MethodB would be implemented on the next release of the app.

A: 

Depends on the language you are using, but it sounds like the HandlerException class would be abstract and all three methods would be virtual.

If the HandlerException class has absolutely no implementation whatsoever (only defines those three methods) then it would probably make sense to make it an interface rather than an abstract class.

Also, where is MethodB implemented? If it isn't implemented by any of those classes, then all the classes would need to be abstract.

Eric Petroelje
Thanks for you answer. I tried the way you suggest, but I can't create virtual or abstract methods that are static, cause as I mentioned, I need MethodsA, B and C to be static to use them directly without any instance of the class on the child class. Or am I wrong and theres another way?
lidermin
@lidermin - They shouldn't need to be static. If you are calling the method from a child class, you already have an instance - yourself! So, rather than `DataHandler.MethodC` it would just be `this.MethodC` or just `MethodC` for that matter.
Eric Petroelje
Ohhhhh I see now! U clear my mind! Thanks again!
lidermin