DEV Community

Lucas Olivera
Lucas Olivera

Posted on

Static Class or Interface?

Hello guys, this is my first post and it is a question. I've been learning C# and I didn't understand the difference between Static Class and Interface. In essence they appear to do the same, but as I don't have much experience I was wondering if maybe they were the same but with different performance or something like that.
Help?

Top comments (1)

Collapse
 
nektro profile image
Meghan (she/her)

Static class: A Class that can be not instantiated into an Object and only contains functions and other statically accessible declarations.

An Interface: is an extension template you can add on to classes to say what methods they might contain. Say you have a Drivable interface that exposes a .drive method. This interface does not contain an implementation but Car, Truck, and SUV, all implement the Drivable interface. Interfaces come in handy when you want to define a parameter type that doesn't need to know about the implementation, but only that a particular set of methods. The best example of this the the List. You might get a List that uses an array or linked list, but in most cases you just need something you can .push, .pop, .shift, and .unshift to.