mskeel Posted May 12, 2004 Posted May 12, 2004 Is there a way to tell a class that you write that it must be inherited by other classes, similiar to the icontainer class and other i-- classes in .Net? I have a data structure I use in several places, and I want to know what kind of objects I hold in it from use to use. But, I want it to always be inherited and I want to force it so that will happen everytime....no lazy coding. Quote
Arch4ngel Posted May 12, 2004 Posted May 12, 2004 Abstract might be useful. The equivalent of MustInherit in VB.NET. Quote "If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown "Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me "A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend. C# TO VB TRANSLATOR
mskeel Posted May 12, 2004 Author Posted May 12, 2004 MustInherit...so easy, yet at first, so elusive. That put me on the right track, thank you very much. Quote
Arch4ngel Posted May 12, 2004 Posted May 12, 2004 No problem... as it said in the Microsoft help... you can always put variables and initialize them at declaration but you can't implement anything in your functions. You'll only have to write the header. Quote "If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown "Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me "A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend. C# TO VB TRANSLATOR
Arch4ngel Posted May 12, 2004 Posted May 12, 2004 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbconAbstractClassesVersusInterfaces.asp Look at this also... Interface programming. Have similarity with Abstract but... have some useful things in it. Like they say... it's your final decision. Quote "If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown "Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me "A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend. C# TO VB TRANSLATOR
Administrators PlausiblyDamp Posted May 12, 2004 Administrators Posted May 12, 2004 (edited) If you mark a class as MustInherit you can provide functionality - this is the main reason for using an abstract (MustInherit) class over an interface, sub classes gain the base class functionality and can be used anywhere it is expected but the sub classes can also provide additional functionality or override the base classes implementation of a function (providing the base class allows this). If an individual function is marked as MustOverride then you cannot provide any implementation in the MustInherit class - classes that derive from it must provide their own implementation. There is a lot more to deciding between Interfaces / abstract classes than I've covered here and the points mentioned aren't enough to make that decision accurately - a proper design phase with decent analysis would be required for all but the most trivial of scenarios. Edited February 27, 2007 by PlausiblyDamp Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
mskeel Posted May 12, 2004 Author Posted May 12, 2004 Thank you very much for the wealth of information... So I could make a special hash table with added functionality, say, and then make it so it could accept special object keys. But since I don't know what the special keys might be, I could stub out an abstract function like MakeKey() and then require that the user implement it when they inherit to meet the specific needs of the class they are creating...? that would be sweet. Quote
Arch4ngel Posted May 12, 2004 Posted May 12, 2004 Yeah ! Really pleasant working with Abstract class and Interface. Have fun with it. But remember... I good thinking before choosing is always good. Before choosing which one you want... look at PlausiblyDamp recommendation and read the little article in my last post. Quote "If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown "Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me "A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend. C# TO VB TRANSLATOR
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.