Contents
Can a concrete class implement an interface?
A concrete class is a class that has an implementation for all of its methods. They cannot have any unimplemented methods. It can also extend an abstract class or implement an interface as long as it implements all their methods. It is a complete class and can be instantiated.
How many interfaces can a concrete class implement?
Any abstract methods are overridden, to include a method body. A concrete class can implement multiple interfaces, but can only inherit from one parent class. In the example below, the Dog class inherits its methods from the interface, Pet , and the abstract class, Animal .
What is a concrete interface?
Interface is a blueprint for your class that can be used to implement a class ( abstract or not); the point is interface cannot have any concrete methods. Concrete methods are those methods which have some code inside them; in one word – implemented. What your interface can have is static members and method signatures.
Can concrete class extend abstract class?
A concrete class is a conventional term used to distinguish a class from an abstract class. And an abstract class cannot be instantiated, only extended. An abstract class can extend another abstract class. And any concrete subclasses must ensure that all abstract methods are implemented.
Is ArrayList a concrete class?
Some examples of concrete classes from the JDK are HashMap, HashSet, ArrayList, and LinkedList.
When to use interfaces instead of concrete types?
Normally always use interfaces instead of concrete types (on lists, injectable services and so forth). For example in lists i just pass Stack Exchange Network
When to use abstract and concrete types in DTOs?
In general, you want to accept as abstract a type as possible, and return as concrete a type as possible, but the situation you came across isn’t really a question of abstract vs. concrete types. If you want the caller to be responsible for making sure an argument is serializable, that needs to be specified in the interface.
Do you really need to support everything that implements IList?
That being said, the C# syntax for parameters that require multiple interfaces is inane. There’s a YAGNI argument to be made that do you reallyneed to support everything that implements IList? Is it worth the trade off in readability?