4 Replies - 3570 Views - Last Post: 21 April 2011 - 09:41 AM

#1 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2262
  • View blog
  • Posts: 9,464
  • Joined: 29-May 08

The Pros & Cons of Applied Inheritance

Post icon  Posted 20 April 2011 - 09:13 AM

Inheritance is when a class inherit properties and methods of a base class.
A lot of you should be already using inheritance in your projects.

But have any of used inheritance, in situations not often considered.

For example;- Form Inheritance
Public Class UI_StandardUser
  Inherits System.Windows.Form

End Class



Public Class UI_AdminUser
  Inherits UI_StandardUser

End Class


The form UI_AdminUser, has all of the buttons and controls of the UI_StandardUser form, but now can extended to have controls specific to the role of Admin.



What are thoughts about using Inheritance in this way? Have you use it in your code?
What are the Pros? What are the Cons?

Is This A Good Question/Topic? 1
  • +

Replies To: The Pros & Cons of Applied Inheritance

#2 lordofduct  Icon User is offline

  • I'm a cheeseburger
  • member icon


Reputation: 2533
  • View blog
  • Posts: 4,633
  • Joined: 24-September 10

Re: The Pros & Cons of Applied Inheritance

Posted 20 April 2011 - 11:41 AM

I have.

But in VisualStudio not w/ controls in the parent Form class because the Visual Studio designer doesn't know how to deal with it (or if it does, I don't know how to make it deal with it... aside from templates).

I have used it in other frameworks. Like Flex w/ Actionscript. I have created generic components that could be extended and expanded upon. Very useful for templating through inheritance there as well.
Was This Post Helpful? 0
  • +
  • -

#3 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2262
  • View blog
  • Posts: 9,464
  • Joined: 29-May 08

Re: The Pros & Cons of Applied Inheritance

Posted 20 April 2011 - 01:10 PM

An Example
Public Class Form1

    Private Sub But_Bell_Click(sender As System.Object, e As System.EventArgs) Handles But_Bell.Click
        MessageBox.Show("Ding a ling")
    End Sub
End Class



Attached Image
Public Class BellsAndWhistles
    Inherits Form1
 
End Class


Attached Image


You'll need to (re)build the project so the inheritance correctly propergates.

I've added a button and changed the form's title.

Attached Image

Attached Image
Was This Post Helpful? 0
  • +
  • -

#4 lordofduct  Icon User is offline

  • I'm a cheeseburger
  • member icon


Reputation: 2533
  • View blog
  • Posts: 4,633
  • Joined: 24-September 10

Re: The Pros & Cons of Applied Inheritance

Posted 20 April 2011 - 01:12 PM

Never tried it in VS2010, VS2008 bugs out randomly and crashes if you do that.

This post has been edited by lordofduct: 20 April 2011 - 01:12 PM

Was This Post Helpful? 0
  • +
  • -

#5 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2262
  • View blog
  • Posts: 9,464
  • Joined: 29-May 08

Re: The Pros & Cons of Applied Inheritance

Posted 21 April 2011 - 09:41 AM

Ran into a small issue with Form Inheritance. See my StackOverflow Question for issue and solution.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1