The code I'm working with has an empty interface:
public interface ICube {}
It has no methods or properties.
Some classes implement ICube
and other interfaces inherit from ICube
.
Please someone tell me how that ICube interface could be beneficial?
An empty interface does not define any members. Therefore, it does not define a contract that can be implemented. If your design includes empty interfaces that types are expected to implement, you are probably using an interface as a marker or a way to identify a group of types.
The purpose of interfaces is to allow the computer to enforce these properties and to know that an object of TYPE T (whatever the interface is ) must have functions called X,Y,Z, etc.
It is an empty interface (no field or methods). Examples of marker interface are Serializable, Cloneable and Remote interface.
Implementing an empty interface tells the compiler to do some operations. It is used to logically divide the code and a good way to categorize code. It is more useful for developing API and in frameworks like Spring.
You should read from MSDN about Interface Design
https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/interface
✓ DO define an interface if you need some common API to be supported by a set of types that includes value types.
✓ CONSIDER defining an interface if you need to support its functionality on types that already inherit from some other type.
X AVOID using marker interfaces (interfaces with no members).
If you need to mark a class as having a specific characteristic (marker), in general, use a custom attribute rather than an interface.
✓ DO provide at least one type that is an implementation of an interface.
Doing this helps to validate the design of the interface. For example, List is an implementation of the IList interface.
✓ DO provide at least one API that consumes each interface you define (a method taking the interface as a parameter or a property typed as the interface).
Doing this helps to validate the interface design. For example, List.Sort consumes the System.Collections.Generic.IComparer interface.
X DO NOT add members to an interface that has previously shipped.
More reference: Empty interface Are empty interfaces code smell?
Marker interface What is the purpose of a marker interface?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With