Unity Interfaces vs Abstract Classes - Part 1 - Interfaces
Video Statistics and Information
Channel: Jason Weimann
Views: 49,546
Rating: undefined out of 5
Keywords: Unity3D Interface, Unity Abstract Class, Unity Interface, C# Interface, Unity3D Abstract Class, Abstract Class vs Interface
Id: kYJRIWjoeFA
Channel Id: undefined
Length: 10min 10sec (610 seconds)
Published: Sun Sep 10 2017
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.
I find a lot of people have trouble understanding the use / benefit of interfaces. To anyone that's interested, but struggling with this idea, here's an analogy I use when mentoring junior devs:
An interface is the blue print specification for a given class. Take an auto factory - at Toyota they build a slot for the radio to fit. When an after market company wants to build a radio, they need specifications like the height and width of the radio slot, the wiring harness to make it work with the car, and possibly an adapter to make the radio fit in the Toyota slot.
All of these constraints would go into an IRadio interface that would look something like:
interface IRadio { double Width{get;}
double Height{get;} double Length{get;}
//Wire harness Info int[,] WireHarnessLayout{get;} //Typically 2/10 or 2/12
// Position in Matrix Vector2 PowerWire1; Vector2 PowerWire2; Vector2 UpVolume; Vector2 DownVolume; //Etc... }
And so when powering on the radio, Toyota can check the values on your interface implementation, and (hopefully) shut down the power before you blow up your radio. Other things like the physical wire harness and radio spec will obviously not fit if you don't match up to Toyota, or you have to create an adapter ( just like an adapter pattern in the software world).
In software, all of this allows the concept of "loose coupling" - something that's critical for having stable, scallable software. it won't guarantee those things, but makes it much easier to do. It's part of SOLID principals, something that doesn't make it into games that often, but is everywhere in enterprise application development.
Hope that helps!