Interface vs. Abstract Classes

Abstract class

  • Used as a base class for the same type of objects (for example, enemies)
  • Can have methods, properties, events, and indexers
  • Can declare and assign values to variables and implement methods
  • Can have abstract methods (with empty body, forced to be implemented by child classes)
  • Can contain different access modifiers such as public, private and protected
  • A class can inherit only one abstract class
  • With polymorphism, method’s implementation can be shared, modified or cancelled
  • Can be fully or partially implemented
  • Faster performance

Interfaces

  • Only can declare methods, properties, events, and indexers
  • A class can inherit from multiple interfaces
  • It contains mandatory public access modifier because access to everything in the interface must be allowed from any other script
  • Slower performance because it needs to search and find the corresponding class and method
  • Can contain methods, properties, events, and indexers
  • It is required, mandatory to be fully implemented (it is like a contract)
  • It can be used for multiple types of objects (for instance, IDamageable can be used for player and enemies)

Important additional information:

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Deploy AWS Fargate Clusters with Pulumi

Meet Candace Ramsarran — Systems Administrator at Zero Hash

Largest Values From Labels

How to Execute Raw SQL Queries on Multiple Databases in Django

BrowserStack Announces the Launch of BrowserStack Champions

BrowserStack Champions, Trending in Testing, Photo from https://www.browserstack.com/

Open Source and Interporality in the Metaverse

🚀 Airdrop: Soldex & Alfprotocol Giveaway 💰 Value: 2500$ SOLX & ALF 📅 End Date: 24th April, 2022…

Celebrating 1 Month on Avalanche

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Hernando Nieto Jaramillo

Hernando Nieto Jaramillo

Unity developer

More from Medium

My journey becoming a Unity game developer: 2.5D Infinite Runner-Ledge Grab System-Pt4

Hidden Shortcuts to Make Level Design Easier in Unity.

Day 102: Character Animation Part 5

Understanding IDamageable Interfaces (part 1)