August 16, 2003
"Benji Smith" <dlanguage@xxagg.com> a écrit dans le message de news:h2ikjv8f8bf6h09fnamt6ivuehqb5401vv@4ax.com...
> Here's an idea that I've been aching for in several different languages: method blocking.
>
> I often create base classes that will have lots of different kinds of derived classes. To avoid duplicating code, I put all the method definitions in the base class, so that they can be inherited by the derived classes that really need them. But not all of the derived classes should have access to all of the methods in the parent class, and I'd like to block them.
>
> Take a look at this code:
>
> class baseClass {
> public void doSomething() {
> ...
> }
> }
> class derivedClassA: baseClass {
> public void doSomethingFun() {
>
> }
> }
> class derivedClassB: baseClass {
> block void doSomething();
> }
>

In pratice, if someone want to block one method then the design is probably bad...

Also block a method does not works well with public inheritance since we can access the method with a base pointer but not a derived one. Thus, it would have to be combined with another inheritance (protected or private).

I don't know if D check access after having found a method. If so then it would be usefull to have a modifier "hidden" so that the compiler would not consider the object as one of its base type (it would just allows overring virtual methods).


1 2
Next ›   Last »