Compositional Relationships - You've Already Been Using Them | Unity C# Basics 7




Published: 06 Sep 2022

With this tutorial, aimed at absolute beginners who have very little to no coding experience whatsoever, you'll learn what Composition is and how to use it (you already are using it!). You'll learn when to use a compositional relationship versus an inheritance relationship and what the benefits are for favoring Composition over Inheritance.


If you've been using Unity for a while, or are just getting started with Unity and decided it's time for you to start learning how to write code - this is the video series you need to start your programming journey!


The AutoDestroyText/CountDownAutoDestroyText code referenced in this video is available, as always, on GitHub: https://github.com/llamacademy/unity-csharp-basics-6

This video we didn't implement anything new, so there's no new repository!


๐Ÿ“๐Ÿ“๐Ÿ“YOUR HOMEWORK!๐Ÿ“๐Ÿ“๐Ÿ“


Do some data modeling for enemies that can attack the player. Starting with 3 types:

1. Melee enemy

2. Ranged enemy

3. Boss enemy

4. Ranged and Melee attacking enemy.


Revisit your last homework to create inheritance and compositional relationships and interfaces to allow you to group common code and variables, define "can-do" relationships that allow you to extend what enemies and bosses can do in the future without significant rework.


๐Ÿท๏ธSave 25% on the ultimate C# IDE: JetBrains Rider with code LLAMACADEMY: https://www.jetbrains.com/store/?section=personal&billing=yearly


๐Ÿ“š Resources ๐Ÿ“š

โšซ Further reading on the topic: https://scottlilly.com/c-design-patterns-composition-over-inheritance/

โšซ C# Fundamentals - Inheritance: https://docs.microsoft.com/en-us/dotnet/csharp/fundamentals/tutorials/inheritance

โšซ C# Access Modifiers: https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/access-modifiers

โšซ C# Interface: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/interface

โšซ C# Virtual: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/virtual

โšซ C# Overriding methods: https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/knowing-when-to-use-override-and-new-keywords


Full Series Playlist Here: https://www.youtube.com/watch?v=SXaa61JWLDw&list=PLllNmP7eq6TTjwoyfRYAAFOH1sMHVgI1r


โšซ Part 1 - Writing your first script

โšซ Part 2 - Loops and Arrays

โšซ Part 3 - Unity Component Lifecycle

โšซ Part 4 - Static vs Instances

โšซ Part 5 - Delegates

โšซ Part 6 - Inheritance & Interfaces

โšซ Part 7 - You are here ๐Ÿ˜‰


๐Ÿงก Believe in LlamAcademy's mission and have received value from the videos? Here's how you can show your support:

๐ŸŒŸ Patreon: https://www.patreon.com/llamacademy

๐ŸŒŸ YouTube Member: https://www.youtube.com/channel/UCnWm6pMD38R1E2vCAByGb6w/join or click the Join button on any video

๐Ÿ“š Take my Unity ShaderGraph Course:

https://www.gamedev.tv/p/unity-shader-graph?affcode=45216_kuvg0bp7

๐Ÿ‘• Get yourself some LlamAcademy merch: https://llamacademy.myspreadshop.com/

๐Ÿ’ธ Use my Affiliate Link for Humble Bundles https://humblebundleinc.sjv.io/9g4ak4

๐Ÿ’ธ Publisher Sale! 50% OFF an entire publisher's Assets! Publisher changes weekly! https://assetstore.unity.com/publisher-sale?aid=1101l9QvC (affiliate)

๐Ÿ’ธ Save up to 50% on NEW Assets: https://assetstore.unity.com/?new_sale=true&orderBy=1&aid=1101l9QvC (affiliate)


Some links may be affiliate links, which at no additional cost to you, gives me a small portion of the purchase.


Connect on Social Media

Some links may be affiliate links, which at no additional cost to you, gives LlamAcademy a small portion of the purchase.