D - Abstract Classes
- Don Stewart (15/15) May 21 2002 I have a base class Foo that I have defined as abstract. Derived from th...
- Don Stewart (5/20) May 21 2002 Okay so I should make the variable private in Foo :o)
- OddesE (21/36) May 23 2002 method
- Don Stewart (9/50) May 23 2002 this
- Pavel Minayev (8/10) May 24 2002 Just declare its constructor as private. It is the way it was done
- Don Stewart (6/16) May 24 2002 Yes of course. I seen the years of Java have killed off the C++ brain ce...
I have a base class Foo that I have defined as abstract. Derived from this is class Bar. I get an error compiling Foo as it's construcotr has a method body. This is what I am trying to do :- abstract class Foo { protected int a; this( int a ) { this.a = a; } } class Bar : Foo { this ( int a ) { super ( a ); } } Is this supposed to fail in D ?
May 21 2002
Okay so I should make the variable private in Foo :o) However, the question remains. "Don Stewart" <donald.m.stewart btinternet.com> wrote in message news:acgvf6$1hou$1 digitaldaemon.com...I have a base class Foo that I have defined as abstract. Derived from this is class Bar. I get an error compiling Foo as it's construcotr has amethodbody. This is what I am trying to do :- abstract class Foo { protected int a; this( int a ) { this.a = a; } } class Bar : Foo { this ( int a ) { super ( a ); } } Is this supposed to fail in D ?
May 21 2002
"Don Stewart" <donald.m.stewart btinternet.com> wrote in message news:acgvf6$1hou$1 digitaldaemon.com...I have a base class Foo that I have defined as abstract. Derived from this is class Bar. I get an error compiling Foo as it's construcotr has amethodbody. This is what I am trying to do :- abstract class Foo { protected int a; this( int a ) { this.a = a; } } class Bar : Foo { this ( int a ) { super ( a ); } } Is this supposed to fail in D ?Mmm... I thought abstract classes should have no implementation? I know it is possible to do this in C++, but why it should be done I don't understand... Do you want to force the programmer deriving a class from Foo to implement certain functions? Then why not make just the functions abstract? On another note you might want to look into interfaces as a substitute for Abstract Base Classes in D... -- Stijn OddesE_XYZ hotmail.com http://OddesE.cjb.net _________________________________________________ Remove _XYZ from my address when replying by mail
May 23 2002
"OddesE" <OddesE_XYZ hotmail.com> wrote in message news:acjm92$137a$2 digitaldaemon.com..."Don Stewart" <donald.m.stewart btinternet.com> wrote in message news:acgvf6$1hou$1 digitaldaemon.com...thisI have a base class Foo that I have defined as abstract. Derived fromBecause I want to create a class that has fields and methods that can manipulate the fields BUT not the class to be new'ed. Only derived classes can be newed. It's in C++, it's in Java, I wondered why it was not in D. An interface would mean I have to add the fields to all implementing classes rather than using the base class.is class Bar. I get an error compiling Foo as it's construcotr has amethodbody. This is what I am trying to do :- abstract class Foo { protected int a; this( int a ) { this.a = a; } } class Bar : Foo { this ( int a ) { super ( a ); } } Is this supposed to fail in D ?Mmm... I thought abstract classes should have no implementation? I know it is possible to do this in C++, but why it should be done I don't understand... Do you want to force the programmer deriving a class from Foo to implement certain functions? Then why not make just the functions abstract?On another note you might want to look into interfaces as a substitute for Abstract Base Classes in D... -- Stijn OddesE_XYZ hotmail.com http://OddesE.cjb.net _________________________________________________ Remove _XYZ from my address when replying by mail
May 23 2002
"Don Stewart" <donald.m.stewart btinternet.com> wrote in message news:ackskg$2b2m$1 digitaldaemon.com...Because I want to create a class that has fields and methods that can manipulate the fields BUT not the class to be new'ed.Just declare its constructor as private. It is the way it was done in C++, and I think it should be done so in D as well. Abstract class is a class with all members abstract. If you only want to define some of the members abstract, just use the "abstract" attributes on them. You still can't create such class, but you can define bodies for non-abstract methods.
May 24 2002
Yes of course. I seen the years of Java have killed off the C++ brain cells :o) My brain hasn't managed to context switch yet LOL Don "Pavel Minayev" <evilone omen.ru> wrote in message news:acl7ni$4ed$1 digitaldaemon.com..."Don Stewart" <donald.m.stewart btinternet.com> wrote in message news:ackskg$2b2m$1 digitaldaemon.com...Because I want to create a class that has fields and methods that can manipulate the fields BUT not the class to be new'ed.Just declare its constructor as private. It is the way it was done in C++, and I think it should be done so in D as well. Abstract class is a class with all members abstract. If you only want to define some of the members abstract, just use the "abstract" attributes on them. You still can't create such class, but you can define bodies for non-abstract methods.
May 24 2002