Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: oops
What is the background mechanism to call an abstract class method in other class(inheritance) without making the the object of abstract class?
 
[Edit]Shouting removed[/Edit]
Posted 23-Feb-13 0:46am
Edited 23-Feb-13 0:48am
ProgramFOX127.7K
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi!! Good question..
 
>Abstract Classes
 
An abstract class is the one that is not used to create objects. An abstract class is designed to act as a base class (to be inherited by other classes). Abstract class is a design concept in program development and provides a base upon which other classes are built. Abstract classes are similar to interfaces. After declaring an abstract class, it cannot be instantiated on it's own, it must be inherited. Like interfaces, abstract classes can specify members that must be implemented in inheriting classes. Unlike interfaces, a class can inherit only one abstract class. Abstract classes can only specify members that should be implemented by all inheriting classes.
 

why we use this
 
Abstract classes allow you to provide default functionality for the subclasses. Common knowledge at this point. Why is this extremely important though? If you plan on updating this base class throughout the life of your program, it is best to allow that base class to be an abstract class. Why? Because you can make a change to it and all of the inheriting classes will now have this new functionality. If the base class will be changing often and an interface was used instead of an abstract class, we are going to run into problems. Once an interface is changed, any class that implements that will be broken. Now if its just you working on the project, that’s no big deal. However, once your interface is published to the client, that interface needs to be locked down. At that point, you will be breaking the clients code.
 
Speaking from personal experiences, frameworks is a good place to show when and where to use both an abstract class and an interface. Another general rule is if you are creating something that provides common functionality to unrelated classes, use an interface. If you are creating something for objects that are closely related in a hierarchy, use an abstract class. An example of this would be something like a business rules engine. This engine would take in multiple BusinessRules as classes perhaps? Each one of these classes will have an analyze function on it.
 
public interface BusinessRule{
Boolean analyze(Object o);
}
 
This can be used ANYWHERE. It can be used to verify the state of your application. Verify data is correct. Verify that the user is logged in. Each one of these classes just needs to implement the analyze function, which will be different for each rule.
 
Where as if we were creating a generic List object, the use of abstract classes would be better. Every single List object is going to display the data in a list in some form or another. The base functionality would be to have it go through its dataprovider and build that list. If we want to change that List object, we just extend it, override our build list function, change what we want and call super.buildList();
 
Almost everyone knows that interfaces means you are just defining a list of functions and that abstract classes has the option of providing default functionality. The snags come when you drop the ‘why would I use one over the other?’. Abstract classes and interfaces are some of the most important fundamentals of object oriented programming. Just knowing the differences between the two is not enough. When you can look at a situation and make a strong recommendation, you will known you have a much stronger knowledge of object
 
Reference From:-http://codeofdoom.com/wordpress/2009/02/12/learn-this-when-to-use-an-abstract-class-and-an-interface/[^]
  Permalink  
v2
Comments
ProgramFOX at 23-Feb-13 6:07am
   
Why you don't post a link to this web page?
http://codeofdoom.com/wordpress/2009/02/12/learn-this-when-to-use-an-abstract-class-and-an-interface/
You copied "why we use this" from there.
CPallini at 23-Feb-13 6:10am
   
:-D
Good catch!
ProgramFOX at 23-Feb-13 6:16am
   
Thank you!
KARTHIK Bangalore at 13-Jan-14 21:20pm
   
:)
CShubham at 23-Feb-13 6:10am
   
because question is unique and answer will must be unique if you providing a link so he not get proper answer..
Marcus Kramer at 23-Feb-13 10:24am
   
ProgramFOX did not mean you should provide only link as an answer. He meant that when you copy/paste a portion of text from another site/source, you should provide a link to that source as a reference. onurag19 has updated your solution with a link to show you what we mean. Cheers.
CShubham at 23-Feb-13 6:16am
   
thanks onurag19
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Do you mean what is the mechanism for implementing polymorphism? One possible mechanism is late binding, see "Polymorphism in object-oriented programming" at Wikipedia[^].
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Here is a good article on Importance of Abstract classes and Interfaces -
 
Importance of Abstract classes and Interfaces
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 304
1 Sergey Alexandrovich Kryukov 255
2 Shweta N Mishra 216
3 Maciej Los 210
4 PIEBALDconsult 184
0 OriginalGriff 7,660
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,586
3 Manas Bhardwaj 4,946
4 Maciej Los 4,665


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 13 Jan 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100