|
-
Jul 23rd, 2010, 04:00 AM
#1
Thread Starter
Fanatic Member
Abstract class situation to use
I tried to get knowledge on when to use abstact class and when to use interface. i found some explanaiton in the below path.
http://msdn.microsoft.com/en-us/libr...1d(VS.71).aspx
If you anticipate creating multiple versions of your component, create an abstract class. Abstract classes provide a simple and easy way to version your components. By updating the base class, all inheriting classes are automatically updated with the change. Interfaces, on the other hand, cannot be changed once created. If a new version of an interface is required, you must create a whole new interface.
So is there any sample code which demostrate this differnece in using? please share with me so that i will get very good clarity on situation to use this. please
-
Jul 23rd, 2010, 08:30 AM
#2
Re: Abstract class situation to use
The difference can't be shown in code, you have to understand them. First of all, an interface has no functionality, it describes which properties and methods a class, implementing the interface, at least has. An abstract class can have functionality.
If the functionality is used by external parties, you should write an interface and never change that interface again, for internal use an abstract class can be changed
-
Jul 23rd, 2010, 09:57 AM
#3
PowerPoster
Re: Abstract class situation to use
to elaborate on the existing response: interfaces cannot be instantiated but only implemented in classes. they also must implement all methods or properties exposed in the interface and is public.
abstract classes may contain some code/functionality and has the option of letting the deriving classes override members or methods in the base class/abstract class and acts as a foundation for all classes, combining common features in the abstract class from which the inheriting classes can derive from and call to perform some action.
-
Jul 26th, 2010, 02:21 AM
#4
Thread Starter
Fanatic Member
Re: Abstract class situation to use
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|