‎2012 Jul 19 11:22 AM
Hi experts,
Why we need abstract class ??? we can also perform all the task from a simple class also...Looking for a solid answer ....
Moderator Message: Please search before posting.
Message was edited by: Suhas Saha
‎2012 Jul 19 11:53 AM
Hiii,
Classes which contain one or more abstract methods or abstract properties, such methods or properties do not provide implementation. These abstract methods or properties are implemented in the derived classes (Sub-classes).
Abstract classes does not create any instances to that class objects
We can define some common functionality in Abstract class (Super-class) and those can be used in derived classes (Sub classes).
If you make normal class and now if you want some different logic for different company than when you change logic in original one than it will affect all the programs where you had used that class, Instead of that you just create class as a abstract and as per different company scenario you can create just implementation class which contain logic as per your scenario or if other functionality required than you can create just new method in your child class now you can say - WE CAN MAKE DIFFERENT classes for each scenario but if you want use re usability feature of OOPS than you should go with ABSTRACT CLASS so that it is easy to understand means just you reuse a ready made class by inheriting it and implementing your own logic as per requirement .
‎2012 Jul 19 12:09 PM
Hi Noufal ,
Yes we know that we can perform all task from a simple class , but we still make use of abstract class. The very reason to this cannot be figured out easily because its a matter of choice or you may say its a situation , whether you want to or do not want to.
I prefer to make a "skeleton" (abstract) and put it in different physical "body" which may work differently , but rather would I need that my invented skeleton should be workable ?....................i think NO, no use.
Lets talk in more simple ways , what is abstract class , its use ?
An abstract class is useful when you want to define part of the implementation of an object, but want to leave other parts up to the derived class. One key thing to remember about abstract classes is that they cannot be instantiated by themselves, because they typically lack a complete implementation as well as the fact that abstract keyword tells it can't be instantiated. Yes, you can supply dummy implementations, but why? The whole point is that abstracts are.. well.. abstract.
Imagine you have a class Cat, and this class derives from a class Animal. There is no such thing as an Animal object, it's just a "type". You can't instantiate an Animal because there is no actual Animal in the real world, there are only creatures that are of the type Animal. You can treat different creatures as a common Animal type, but there can't exist a real Animal, it's just a concept.
An Animal would be an abstract type, because the concept of the Animal is abstract. The same is true in software. You might have the concept of an object, such as a Stream. Is it a NetworkStream? A FileStream? A MemoryStream? Stream is just a concept.
So , we can say an abstract is just as a concept , which is just being developed to be implemented by other .
Thanx & Regards ,
Yogendra Bhaskar