How do you combine abstract classes with interfaces in C#?

Good Morning,

I have a question about comprehension. In C#, we have abstract classes, which are intended as base classes for more specific classes, and then we have interfaces, which serve as a kind of contract or specification. My question is, what would the structure look like if we wanted to combine interfaces and abstract classes? What I think it would look like would be: For example, interface -> worker -> abstract class -> worker -> and then the more specific classes.

1 vote, average: 1.00 out of 1 (1 rating, 1 votes, rated)
You need to be a registered member to rate this.
Loading...
Subscribe
Notify of
2 Answers
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Suiram1
9 months ago

From your understanding, everything is true. In your example, however, I would not use I workers and abstract workers. However, I would not have workers as a standard implementation of Iworkers as abstracts, as it always depends on what these classes/interface would like to use.

Another note in the formulation:

would look like the structure

Clearly, in the context classes are meant, however, in C# there are also structs (structures) and without context they could also be meant.

cleanercode
9 months ago

Question: What is the difference between abstract classes and interfaces?

If you don't notice a major difference, the question is why you want to use an interface and an abstract class.

A well-known set from the OOD: "Composition over Inheritance".