What is the difference between an abstract object and an interface class in C #?

What is the difference between an abstract object and an Interface class in C #?

+4
source share
8 answers

The interface is not a class , it is just a contract that defines the publicly available members that the class should strong> implement.

An abstract class is just a class from which you cannot create an instance. Usually you should use it to define a base class that defines some virtual methods for derived classes to implement.

+8
source
+2
source

A class can implement several interfaces, but only one abstract class can inherit.

An abstract class can provide an implementation of methods for it. An interface cannot provide an implementation.

+1
source

Google is an “abstract class versus interface” and you’ll get a lot of explanatory articles ...

+1
source

interface level above abstract.
when you create strcuture, draw uml, u should use the interface.
when u're implemented, then u must use abstract to extract duplicate things.

in any case, different - this is not only a syntax problem.
hope this helps.

+1
source

A class can implement several interfaces, but can only inherit one abstract class.

In addition, abstract classes may have certain functions, but interfaces will not have any function definition, and the receiver class must define all of them.

0
source

I will explain this using use. An abstract class can be used when there is only one hierarchy, additionally without a default implementation; while an interface can be used hierarchically (horizontally), often called behavior.

The interface is also an abstraction, and in C # replaces inheritance with several classes, so this can be confusing, but you have to distinguish when to use what.

Hope this helps, Robert

0
source

The goal of an abstract class is to provide a definition of a base class for how a set of derived classes will work, and then let programmers populate the implementation in derived classes. When we create an interface, we basically create a set of methods without any implementation, which should be overridden by the implemented classes. The advantage is that it provides a way for the class to be part of two classes: one from the inheritance hierarchy and one from the interface.

0
source

Source: https://habr.com/ru/post/1343598/


All Articles