Hi,
Sorry for this simple question, but i am still confused about this.
What is abstraction in OOPs Hw can we implement this in C# is it anything related to abstract class
can anyone help me with examples in C#
thanks in advance..!
Visual C# Language
shinu wrote:
Hi,
Sorry for this simple question, but i am still confused about this.
What is abstraction in OOPs Hw can we implement this in C# is it anything related to abstract class
can anyone help me with examples in C#
thanks in advance..!
Lassie
the Dog
may be treated as a Dog
much of the time, a Collie
when necessary to access Collie
-specific attributes or behaviors, and as an Animal
(perhaps the parent class of Dog
) when counting Timmy's pets.Car
would be made up of an Engine, Gearbox, Steering objects, and many more components. To build the Car
class, one does not need to know how the different components work internally, but only how to interface with them, i.e., send messages to them, receive messages from them, and perhaps make the different objects composing the class interact with each other.""abstraction" and "abstract" are different. An abstraction is a generalization, something that has very little dependencies or is very loosely coupled. An abstract class is one that isn't fully implemented, it's meant only to be derived from and to have its abstract methods overridden.
Abstraction is concerned with hiding, or providing detail at a later date. An class that is abstracted is something where you provide an interface that must be implemented within the class, but that class itself contains no implementation itself.
The difference between an abstract class and an interface is that the abstract methods could be implemented by a derived class as well as the base class providing some functionality, or implementation as well. An interface merely defines the contract the an implementation must adhere to, to be considered able to communicate using that interface.
So a short example could be, and clearly this won't compile, but will give you some ideas and keywords to search on...
public abstract class SomeClass
{
.
.
public abstract void SomeMethod
.
public void AnotherMethod()
{
Console.WriteLine("Hello.")
}
.
}
Then a derived class:
public class SomeOtherClass : SomeClass()
{
// You have to provide the implementation here, as this is abstract...
public void SomeOtherMethod()
{
Console.Writeline("Hello again.");
}
.
// Note that you get AnotherMethod() for "free"...
.
}
I hope this helps you, as the above is a pretty simplistic answer. If it doesn't make sense, shoot me another post, and I'll try again!
Martin.