Inheritance of abstract form

Asked

Viewed 157 times

0

I have a standard form, with a textbox, a search button and a grid; as I intend to use it for several searches, I left an abstract Search() method and at the same time the form as abstract... When inheriting this form, I implement in the child form the Search() method that works normally while running, but this child form is not loaded by the visual studio designer and returns the following error:

The designer must make an instance of type 'Formpesquisa`2[[Formfilho System.Retaguarda.Model, Version=1.0.0.0, Culture=neutral, Publickeytoken=null], but it cannot because the type has been declared as abstract.

  • Just leave the method as abstract

1 answer

1


do not declare the form as abstract, because it must be instantiated!

leave the method as:

public virtual void Pesquisar()
{
throw new NotImplementedException("Método pesquisar não foi implementado");
}

and their children:

public override void Pesquisar()
{
//implementação
}
  • Great idea, but is there any way the IDE can warn you at development time to implement the method? Not to happen to "forget" to implement and end up passing..

  • then believe that not... I once made a software, where all classes inherited from one, that I called Core, and in it there was a method "Getdataset", in the classes you can use interfaces that will alert to a non-implementation when compiling, and in the search form, the object, which was type Core, just called the getDataset method and filled the grid view, I just informed which class would pass to the search form, using the polymorphism

Browser other questions tagged

You are not signed in. Login or sign up in order to post.