Re: Questions of Designs
From: Falk Tannhäuser (falk.tannhauser_at_crf.canon.fr)
Date: 09/10/04
- Next message: Shashank: "Re: Questions of Designs"
- Previous message: Universe: "Re: Questions of Designs"
- In reply to: Shashank: "Re: Questions of Designs"
- Next in thread: Shashank: "Re: Questions of Designs"
- Reply: Shashank: "Re: Questions of Designs"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 10 Sep 2004 18:38:35 +0200
Shashank wrote:
>
> Oh, I don't think am being anti C++ and neither being pro.
> ABC is still a class. In OOPS classes are written so that we may create their objects that will have some
> state and behavior.
>
> While language constructs allow us to create abstract class thats fine. But that is still a class, but we
> are not writing implementation code.
>
> But its not interface. Interface definition should not have option to write implementation code.
What is the advantage for the programmer of not being able to write
implementation code in an interface? There *is* an advantage for
the compiler implementer because it simplifies the implementation
of multiple inheritance - that is the reason why Java has different
keywords 'class' and 'interface', allowing to inherit from multiple
interfaces but at most one class.
However, from the programmer's point of view, the distinction seems
to be quite artificial and limiting to me - very often you want to
put pre-/postcondition checks or otherwise factor out common
behaviour into the ABC and Java interfaces don't let you do that.
C++ example:
class MyAbc
{
virtual result_type do_foo(param_type) = 0; // private
public:
result_type foo(param_type p) // Deliberately not virtual!
{
check_preconditions(p);
result_type r = do_foo(p);
check_postconditions(r);
return r;
}
};
class MyImplemOne : public MyAbc
{
virtual result_type do_foo(param_type p)
{ /* Implementation ... */ }
};
class MyImplemTwo : public MyAbc
{
virtual result_type do_foo(param_type p)
{ /* Another implementation ... */ }
};
Client code would only call foo() and Pre/Postcondition check
will always be performed no matter what derived class you have
to do with. (Yes, I know - in Eiffel, everything is much nicer...)
How would I do the same with a Java 'interface' at the place of
class MyAbc?
BTW, you can't create instances of C++ ABC either.
Falk
- Next message: Shashank: "Re: Questions of Designs"
- Previous message: Universe: "Re: Questions of Designs"
- In reply to: Shashank: "Re: Questions of Designs"
- Next in thread: Shashank: "Re: Questions of Designs"
- Reply: Shashank: "Re: Questions of Designs"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|