Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Examples of Inheritance in C#?

Status
Not open for further replies.

Zoplax

Technical User
Oct 2, 2002
58
0
0
US
I'm building an application which will be part data entry, part data viewing.

Normally I might create separate form classes, one for editing, the other for viewing. However, I'd like to explore using inheritance and interfaces to have a more or less generic "form" class, and from that derive the edit form and view form.

Could someone please point me to examples of this? Or provide a simple one here? Thanks in advance for any help.
 
inheritance will work just as inheritance on any other class but there is a snatch and it is the reason why MS got it out of their marketing thing. It's called collections, all controls that make use of collections will give you problems, to name a few: menu's, toolbars, datagrids, listviews, ... . So it is possible but be carefull and don't use it a lot just use it for basic design.

Christiaan Baes
Belgium

"My new site" - Me
 
I agree - hold off on inheritence unless there's a crystal-clear need for it. Of the three pillars of O-O, I find aggregation to be much more useful.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
could you expand on your point about inheritance?

what makes them a very bad thing, and when?



mr s. <;)

 
Actually it is more of a Inheritance, collections and the designer kind of thing. If you do inheritance and manual coding you will be allright. But the designer get's in to trouble.

Just try it with a mainmenu create a form add a menu and a menuitem and add some menuitems to that. Then inherit from that form and create a new form (or the other way round) and try to delete some of the menuitems or try and add some menuitems in between the others. You will see that the designer doesn't like that. I believe it will even make it impossible to do what you want because it will lock them.

If you want to do some research [google]visual inheritance c#[/google] .



Christiaan Baes
Belgium

"My new site" - Me
 
I found the inheritance in forms within VS fine, just don’t forget to set your modifiers property on buttons etc that children require access to otherwise they get locked for children :)

Myself I usual have the main parent with the close button and then a child may have close, edit, update, delete, that way all the buttons are in the same order no matter how many children the second form has.

I should say using inheritance in forms can be a pain till you get used to it and also unless it will save you a worthy amount of code, don’t bother! If it will save you a lot of redundant code then practice a bit first. My two-pence worth….


Age is a consequence of experience
 
Hmm based on the discussion so far it sounds like it'll be best for me to put off using inheritance in this app I'm creating, it sounds like it's probably too simplistic to benefit greatly from inheritance.

If I were creating some full-fledged data entry or help desk system it might be a better choice, but there just won't be that many objects floating around that will need to be derived from others.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top