What is the need of an interface in this code? C# | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What is the need of an interface in this code? C#

Can purely using inheritance solve this problem. I don't see the need to use an interface https://www.sololearn.com/compiler-playground/c8wu17946fEq

26th Aug 2023, 8:45 AM
Rakan
1 Answer
+ 1
In that simple example, and from a purely functional point of view, no, there's probably not much point. It would be more interesting to do so if Draw had functionality that Brush and Spray would benefit from, and if it made sense to consider a Brush and a Spray as instances of "Draw", which does sound sensible, in the context of a meaningful class hierarchy (although I think the names here are a bit weird, I wouldn't call a class a verb).
26th Aug 2023, 10:55 AM
Marcos Chamosa Rodríguez
Marcos Chamosa Rodríguez - avatar