0

There is a class that I want to create as abstract but I can't because that class's base class is ActiveReports and as soon as I make it abstract the sub-reports are no longer designable. (Interestingly the base class itself IS designable but not it's children).

I know that I cannot declare class members as abstract without first declaring the class as abstract.

In this case what is the NEXT BEST way to do this. At this point I made the members virtual and added comments to each one. Where it made sense I also declared a member as protected rather than public. But is there some other best way that would REQUIRE that these members be overridden at compile-time rather than run-time?

If you were in this situation how would you do it?

EDIT

Let me explain further. I can create a class (lets call it MyReportsBase) that inherits from ActiveReports. (I do that using add new and choose the ActiveReports type) Then ActiveReports provides a property of the report object in MyReportsBase (in design time properties) called MasterClass. Once I set that property to true then I can then create new reports and inherit from MyReportsBase instead of directly from ActiveReports. (The way you do that is by create add new ActiveReports but then edit the code in the code-behind to inherit from MyReportsBase instead of ActiveReports).

That is all well and good and it all works perfectly well. However, my requirement is that MyUpwardBase would HAVE to be inherited (declared abstract with a few abstract members). And I CAN go in the code-behind and set the abstract modifier on the base class. And even then I can design MyReportsBase. However, at that point, all of the reports that I inherited from MyReportsBase are no longer designable. Attempting to open the derived reports in the designer throws an error about how the designer cannot open the base class because it is declared as abstract.

All of this is to just clarify the question. Right now the Interface suggestion is making the most sense to me.

EDIT 2
An Interface doesn't really do it for me either for this reason. The base classes "abtract-but-aren't-abstract" members HAVE To be present in my base classes because I have virtual and public members that depend on them. And in my case, because I cannot declare the class as abstract, I have to have an implementation for those members.

As soon as I provide an implementation for those members then all of my inheriting classes ALSO have the implementation and the Interface doesn't complain at compile time. I thought by removing the virtual modifier from those members that the compiler would require them but it did not behave that way.

I am beginning to think that my solution (document the members well) is the best solution.

Seth Spearman
  • 6,710
  • 16
  • 60
  • 105
  • 2
    Make all child classes also implement an interface? If I understand you correctly ... – Ondrej Janacek Feb 20 '14 at 15:13
  • 3
    Can you clarify a bit which classes are not designable, perhaps with some simple examples? Something as simple as a list to show a hierarchical inheritance tree of a few classes. – Jon Senchyna Feb 20 '14 at 15:13
  • @OndrejJanacek I was thinking along those lines but how do you enforce that the children implement in the interface at compile time? – Liath Feb 20 '14 at 15:14
  • From my understanding, when you make your class `abstract`, ALL sub-classes of YOUR class are not, but `ActiveReports` is. Is this a correct understanding? – Jon Senchyna Feb 20 '14 at 15:15
  • If your classes are not designable, you should be getting an error in the designer (at least from my experience with winforms in Visual Studio). If you are, you could post the error as well. – Jon Senchyna Feb 20 '14 at 15:16
  • How many abstract methods must the children provide? One possibility would be to have a constructor that needs to be passed `Action` or `Func` delegates, which then your "would have been abstract" methods then directly invoke. – Damien_The_Unbeliever Feb 20 '14 at 15:18
  • Check this [http://stackoverflow.com/q/2118055/1565525](http://stackoverflow.com/q/2118055/1565525) – Fabio Jun 07 '15 at 20:46

2 Answers2

0

Why are the base classes of a abstract class that also has a baseclass not designable?

public class Base
{
    public int SomeInt { get; set; }
}

public abstract class BaseChild : Base
{
    public abstract string Value { get; set; }
}

public class ChildChild : BaseChild
{
    public override string Value { get; set; }
}

Works. Or did I misunderstood?

var child = new ChildChild { SomeInt = 3, Value = "asd" };
csteinmueller
  • 2,427
  • 1
  • 21
  • 32
  • @steinmueller. This is not a .net limitation. This is an active reports limitation. See my edits for further clarification. – Seth Spearman Feb 20 '14 at 16:07
  • @SethSpearman To me this an answer to the question. What do you mean by designable? – paparazzo Feb 20 '14 at 16:39
  • By designable I mean that the object can be opened in some kind of reports designer. Think of a Windows Form app. Your form is "designable" in that you can drag/drop controls onto a design canvas and the designer file is updated for you. I probably made that word up. ; / ) – Seth Spearman Feb 20 '14 at 20:10
  • I am still not sure what you are trying to accomplish. Can you help me understand please? Why the need to abstract AR? – Rajnish Sinha Feb 21 '14 at 22:17
0

you dont want to use interface ?

class A: ActiveReport
{
    // some public methods to share between all childs
}

interface IReport
{
    // some required method
}

Class B: A, IReport
{
} 

Class C: A, IReport
{
}
.
.
.
Amir Sherafatian
  • 2,083
  • 2
  • 20
  • 32