Adding member property to abstract class

C

C.E.O. Gargantua

I want to have a member property that is common to a set of classes.

I designed an abstract class, but when I try to add it to the abstract
class, it flags an error in VS.NET.

The design ( summarized is like this ) :


interface interfaceA {
string myMeth();
}

public class abstract ClassA{


// string _myStrValue; // This is what I want to add, but
// the syntax doesn't fit...why?

string myMethod()
{
return void;
}
}

public class myDerivedClassA : ClassA, interfaceA

{


}


--
Texeme
http://texeme.com

incognito () Updated Almost Daily
http://kentpsychedelic.blogspot.com
 
J

Jon Skeet [C# MVP]

C.E.O. Gargantua said:
I want to have a member property that is common to a set of classes.

I designed an abstract class, but when I try to add it to the abstract
class, it flags an error in VS.NET.

The design ( summarized is like this ) :


interface interfaceA {
string myMeth();
}

public class abstract ClassA{


// string _myStrValue; // This is what I want to add, but
// the syntax doesn't fit...why?

string myMethod()
{
return void;
}
}

public class myDerivedClassA : ClassA, interfaceA

{


}

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

The code that you've posted has various potential problems in - there
are no properties at all, you're trying to return void, and you're not
actually implementing the method in the interface.
 
C

CEO Gargantua

The code that I'm working on isn't much difference from what I posted,
because I hit a road block with trying to add a property to an abstract
class...and that's the problem I am posting about.
The code that you've posted has various potential problems in - there
are no properties at all, you're trying to return void, and you're not
actually implementing the method in the interface.

Well, the implementation is taken care of by the abstract class...that
is, its methods act as defaults that handle the requirements of the
interface. Then I can override them using polymorphism for individual
classes that implement the abstract.
Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.


--
incognito...updated almost daily
http://kentpsychedelic.blogspot.com

Texeme Textcasting Technology
http://texeme.com
 
J

Jon Skeet [C# MVP]

CEO Gargantua said:
The code that I'm working on isn't much difference from what I posted,
because I hit a road block with trying to add a property to an abstract
class...and that's the problem I am posting about.

If you could post the *actual* code though, we'd be able to see what's
wrong. As it is, it's hard to know what's wrong in the actual code and
what's just wrong because you've posted code which you haven't tried to
compile.

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.
 
C

C.E.O. Gargantua

Ok, just ignore me.

The answer is "yes, of course".

I just had the wrong syntax when I added the field ( I must have been
dead tired, I didn't add a datatype to it LOL of course it thew an
error, and because I'm new to abstract classes, I /assumed/ that they
were the problem !?! ).


CEO said:
The code that I'm working on isn't much difference from what I posted,
because I hit a road block with trying to add a property to an abstract
class...and that's the problem I am posting about.


Well, the implementation is taken care of by the abstract class...that
is, its methods act as defaults that handle the requirements of the
interface. Then I can override them using polymorphism for individual
classes that implement the abstract.


--
Texeme
http://texeme.com

incognito () Updated Almost Daily
http://kentpsychedelic.blogspot.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top