2 Replies - 2571 Views - Last Post: 26 December 2013 - 07:19 AM Rate Topic: -----

#1 chozokennedy   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 18-December 13

How partial class Form1 inherited from class

Posted 25 December 2013 - 08:31 PM

Hello, I could not make partial class Form1 inherited from another class.
Let say I want to inherited from class B.
I try semicolon and comma, both didn't works for me.
Izit another way to do so ?

 public partial class Form1 : Form



Does not works for me

 public partial class Form1 : Form : Class B


public partial class Form1 : Form, Class B


Is This A Good Question/Topic? 0
  • +

Replies To: How partial class Form1 inherited from class

#2 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 6166
  • View blog
  • Posts: 21,265
  • Joined: 05-May 12

Re: How partial class Form1 inherited from class

Posted 25 December 2013 - 08:36 PM

C# does not support multiple inheritance. You can only inherit from one class. (It does support letting a class expose multiple interfaces.)
Was This Post Helpful? 1
  • +
  • -

#3 Robin19   User is offline

  • D.I.C Addict
  • member icon

Reputation: 272
  • View blog
  • Posts: 552
  • Joined: 07-July 10

Re: How partial class Form1 inherited from class

Posted 26 December 2013 - 07:19 AM

To expand on what Skydiver said and to give you some options to think about:

First option - Have B as an interface. B will have no implementation, but will define certain characteristics. Form1 can implement these characteristics.

Second option - Have B inherit from Form. Then Form1 can inherit from B. Form1 will get all of the Form inheritance from B. This option works best when B's logic is about how the UI is handled. You can have B handle basic UI interactions that are the same throughout your solution. Different forms can all inherit from B and have the same logic behind them without creating copies of the code.

Third option - Have Form1 contain a class variable of B. Form1 will do no work and contain no information. All of that work and information will be contained within B. B will represent your domain. Form1 is simply a way to communicate between the domain and the user. This is the best option. It decouples your code from your UI. You will be able to change your UI (different form, wpf, MVC, etc) without having to change the logic of your code. This also separates your code into different concerns.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1