ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kurt Huwig <k...@iku-netz.de>
Subject Re: Ant2 suggestions
Date Tue, 17 Jul 2001 09:20:13 GMT
Conor MacNeill wrote:
> From: "Maurice le Rutte" <mplr@oce.nl>
> > From: "Kurt Huwig" <kurt@iku-netz.de>
> >
> > > Inheritance of fields is a Bad Thing (tm) IMHO.
> >
> > I've always thought that inheritance of fields was one of the core things
> of
> > OO...
> 
> Well, allowing protected access does break the super class' encapsulation,
> allowing the subclass to violate the class invariant of the super class.
> So, in general, it is a bad thing. Providing accessors is not much better,
> though, unless you can restrict what the caller can do to the object (eg,
> const in C++). In the case of Ant tasks, the project field is not really
> part of the task's invariant, so protected access is not generally harmful.

Accessors allow you to change the internal data representation without
changes to the outer world. If you have to change from one project to
several projects or divide the 'Project' class into several classes, you
just change the 'getProject()' into a fascade and are done. With protected
inheritance, things become evil.

You are right that Java lacks the things you can do in C++ with 'const'. You
can work around it by using an interface containing only getter methods, but
it is not as easy as the C++ approach. On the other hand, you if you want to
make it right, you have to check every access at runtime.

Kurt
-- 
---------------------------------------------------------------
If DOS means "Denial Of Service" what means MS-DOS?
                            And why should I tell it to "win"?

Mime
View raw message