I have always not really liked the idea of using inheritance. The reason why is because there is so much abstraction going on. Let me use a general example outside of programming. Just say you have a door, and it can do many things, it can open, close, lock, and unlock. Instead of going out to the forest and cutting down a tree and building the door, I could go to a manufacturer or hardware store and buy a door. Then I can modify it to do one extra thing, display the street numbers.
Now going back to programming, we could use somebody else's code that already made a class called Door. When we inherit the door, we don't have to make the open() close() lock() and unlock() methods, because somebody already did it for us. All we need to do is add a few lines like this:
public partial class myInheritedDoor : Door
{
// add your methods here
}
It took a little time for me to understand inheritance, but I did discover it is useful because it helps you save time. I would also suggest going to google.com or yahoo.com and type in "c sharp inheritance examples". Better yet to make your life easier, type in "c sharp basic inheritance examples"
No comments:
Post a Comment