When, Why, and How to use Builder and Fluent Builder Programming Patterns

Ойындар

Unity C# Architecture: Insights and examples of when to use the Builder and Fluent Builder Programming Patterns in Unity C# using expert Software Engineering Principles.
🔔 Subscribe for more Unity Tutorials / @git-amend
#unity3d #gamedev #indiedev
▬ Contents of this video ▬▬▬▬▬▬▬▬▬▬
0:00 Code Smells
1:15 Fluent Builder 1
03:47 Fluent Builder 2
6:15 Builder and Director
8:30 Builder using Interfaces
Assets Shown In This Video (Affiliate Links)
Chromisu: Handpainted Forest MEGA Pack assetstore.unity.com/packages...
SineVFX: Better Crystals assetstore.unity.com/packages...
Follow me!
linktr.ee/gitamend

Пікірлер: 77

  • @the_gobbo
    @the_gobbo9 ай бұрын

    In 11 minutes you taught me more than 7 whole classes about software engineering

  • @git-amend

    @git-amend

    9 ай бұрын

    Thank you, that's a very encouraging comment! The channel is definitely starting to grow a little faster lately because of this video, and more like it to come! Cheers!

  • @phoenixfire6559

    @phoenixfire6559

    9 ай бұрын

    @@git-amend You need to leverage your skills as a senior software engineer. Most tutorials/ videos target beginner levels. I've been working through all of yours, and they're all really informative. I also note your consistent release schedule. Just keep at it, once you hit a certain number you'll hopefully get a lot more subs because this channel deserves it. My main advice so far is have a look at your thumbnails, the text is really important and I often see "3D" or "Shoot Em Up" really clearly but can't see the rest - I personally don't think 3D or Shoot Em Up should have been the most prominent words but would have clicked if I had seen Parallax or Player Controller. In this thumbnail, "Game Programming Patterns" was very clear. The fluent builder less so, but I clicked based on programming patterns. Anyways, the video and audio quality are excellent and you are presenting really well. Its more of a case of getting that youtube algorithm to favor you. I've subscribed, hopefully the high quality content continues.

  • @git-amend

    @git-amend

    9 ай бұрын

    @@phoenixfire6559 Thanks for the comments and constructive criticism - it's always welcome. I think you are right about the text; I'm going to make some changes based on that suggestion - thank you!

  • @git-amend
    @git-amend9 ай бұрын

    Leave a comment if there is a particular programming pattern you'd like me to feature in a future episode - already planning Factory, Adapter and Mediator patterns. Hit the bell so you don't miss a thing!

  • @gnendraaw
    @gnendraaw10 күн бұрын

    I am so grateful that I found your channel! Really help me alot learning game programming the better way since I am learning by myself. This is an absolute gem

  • @git-amend

    @git-amend

    9 күн бұрын

    Great to hear! Welcome aboard!

  • @hoaxygen
    @hoaxygen9 ай бұрын

    THANK YOU! I didn't know I needed this knowledge and it fit right into my project, cleaning up a bit of code. It was so cool and easy to implement the builder with interfaces despite its complexity.

  • @git-amend

    @git-amend

    9 ай бұрын

    Awesome! I'm really glad it helped you out!

  • @Hazzel31337
    @Hazzel313372 ай бұрын

    i am still pretty confused about most of your advanced topics, but i am getting there slowly, your content helps, thanks

  • @git-amend

    @git-amend

    2 ай бұрын

    Glad to hear that!

  • @eduardoddutra
    @eduardoddutra8 ай бұрын

    Awesome video! Very well explained! I could definitely watch a playlist of 30 of these video tutorials about other patterns and good practices, it's so hard to identify when to use it, it always looks like magic to me...

  • @git-amend

    @git-amend

    8 ай бұрын

    Thanks! More to come!

  • @rabrar6200
    @rabrar62009 ай бұрын

    nice idea for thumbnail! really caught my eye.

  • @JiwonSong95
    @JiwonSong957 ай бұрын

    This one single video made my understanding of design pattern whole new level. Very high quality content.

  • @git-amend

    @git-amend

    7 ай бұрын

    Wow, thanks!

  • @Broudy001
    @Broudy0019 ай бұрын

    I've learnt so much from your channel, some goes over my head like this one, I'll need to watch it a few more times, and try putting it into a project before I get the hang of it I suspect

  • @git-amend

    @git-amend

    9 ай бұрын

    Absolutely. Try it out a few times, and it will click!

  • @derboss66
    @derboss668 ай бұрын

    This guy is the hero we didn’t know we needed.

  • @switbitz
    @switbitz3 ай бұрын

    Your channel is top tier for advance programming topics not limited to game development. Great work!

  • @git-amend

    @git-amend

    3 ай бұрын

    Glad you think so! Cheers!

  • @popuzin
    @popuzin8 ай бұрын

    Just a comment for support. Good stuff 💪keep it up!

  • @git-amend

    @git-amend

    8 ай бұрын

    Appreciate it!

  • @PurpleDaemon_
    @PurpleDaemon_Ай бұрын

    The last tip with interfaces is awesome!!!

  • @git-amend

    @git-amend

    Ай бұрын

    Right on!

  • @SirSone7
    @SirSone79 ай бұрын

    Hey, even tho you are not as popular as you should be, this channel is a true knowledge treasure for my level so i hope you keep uploading regardless of your views and subs. these are super helpful and your explanations are easy to understand. thank you I would love if you can cover Strategy , Command , State patterns as well

  • @git-amend

    @git-amend

    9 ай бұрын

    I appreciate the comment! Those are great suggestions!

  • @ragerungames
    @ragerungames7 ай бұрын

    Great explanation!! Thank you!

  • @git-amend

    @git-amend

    7 ай бұрын

    You're very welcome!

  • @timurnikolaev1438
    @timurnikolaev14382 ай бұрын

    nice and clear

  • @git-amend

    @git-amend

    2 ай бұрын

    Thank you!

  • @satibel
    @satibel9 ай бұрын

    Congratulations on pleasing the algorithm and hitting that programming/manhwa recap cross section with your thumbnail

  • @git-amend

    @git-amend

    9 ай бұрын

    Thanks! I had a lot of fun with the thumbnail! Stay tuned for more!

  • @SirDMX
    @SirDMX9 ай бұрын

    Pretty useful thank you :D

  • @git-amend

    @git-amend

    9 ай бұрын

    Awesome!

  • @satibel
    @satibel9 ай бұрын

    Depending on what you're doing, you could use what I call self builder, where you merge the builder and the class, so you could have a boolean ready, that you set once the class is set properly (can also have it read only and use an initialization method). That's useful if you need to modify the class a lot and you're not using inheritance, because the builder is somewhat redundant, because you need setters anyway. So instead of Var Eb=new enemybuilder() Eb.health=100 Eb.behavior=behavior.followplayer Var enemy=Eb.build() You have Var E=new enemy() E.health=100 E.behavior=behavior.followplayer E.init() (You can also use that with a fluent builder, where you return this, I did it that way for clarity as it's just an idea, this assumes properties which call setters with that syntax, which aren't available in all languages.) Otherwise you're juggling between 2 or 3 classes for basically no reason. Though where you'd want to use an external builder is if you need to enforce a "non null" (not necessarily null, but there's no desirable default) behavior, like for example, you want every enemy to have their hp or behavior set (could be more complex, like requireing either a sprite or a 3d model), an external builder can just return null, while with a self builder you have to check that it has been initialized. (I.e. with a builder you can't create a class with an invalid state, while with a self builder you can have one)

  • @git-amend

    @git-amend

    9 ай бұрын

    Great insights on the 'self builder' approach! It's a neat way to streamline object creation, especially when inheritance isn't a factor. Thanks for sharing this alternative!

  • @setroid8235
    @setroid82359 ай бұрын

    This is great information! The video would be better if the audio were higher quality, and the intro was better (or simply removed). I don't see very many smaller channels, but the first thing I notice in smaller channels is the lower quality audio. I liked the video. :)

  • @git-amend

    @git-amend

    9 ай бұрын

    Glad you liked the info! Thanks for the feedback - all suggestions are welcome!

  • @Frank_G_Finster
    @Frank_G_Finster8 ай бұрын

    I learned, i liked, i subscribed. I will put this knowledge to good use in my Godot project. Thank you very much.

  • @git-amend

    @git-amend

    8 ай бұрын

    Awesome, thank you! Nice thing about programming patterns is you can use the knowledge in almost all modern programming languages!

  • @AkakiAkakievitch-kc2vk
    @AkakiAkakievitch-kc2vk2 ай бұрын

    There are a lot of tutorials about how to make games, but very few about how to write effective and clean code! Thank you for that. I'll definitely browse carefully the content of your channel! A gold mine!

  • @git-amend

    @git-amend

    2 ай бұрын

    Thanks for the kind words!

  • @axiomgamesofficial
    @axiomgamesofficial9 ай бұрын

    Subscribed!

  • @git-amend

    @git-amend

    9 ай бұрын

    Awesome, welcome to the channel! More great content is on the way!

  • @arjanb7158
    @arjanb71589 ай бұрын

    Using the fluent builder as a child class of a scriptable object finally lets me create instances in tests without making public setters. Amazing!

  • @git-amend

    @git-amend

    9 ай бұрын

    That's a great usecase!

  • @kevin41307
    @kevin413075 ай бұрын

    amazing tutorial...!

  • @git-amend

    @git-amend

    5 ай бұрын

    Haha are you binge watching all the videos? 😀

  • @kevin41307

    @kevin41307

    5 ай бұрын

    @@git-amend yeah, it is really helpful. The real-world example in video are great. I wish I can watch these video earlier. Thanks a lot.

  • @friedcrumpets
    @friedcrumpets8 ай бұрын

    I'd be very curious to see your take on a Composite Tree or even a behaviour tree. I built an implementation after reading a blog post by the developer of Project Zomboid, however I've had some trouble finding great use cases for it. Fantastic tutorials. I really hope your channel gains some traction

  • @git-amend

    @git-amend

    8 ай бұрын

    Great suggestion! I have a related topic already on my todo list, and I'll jot this down as well. Thanks!

  • @trell_7842
    @trell_78427 ай бұрын

    Whooa, Great thx. Now i finnaly understand what difference between the two. Not as big as i excepted.

  • @git-amend

    @git-amend

    7 ай бұрын

    Awesome!

  • @Broudy001
    @Broudy001Ай бұрын

    I finally managed to implement one of the patterns for something useful, I think :S

  • @git-amend

    @git-amend

    Ай бұрын

    Excellent!

  • @6Abdellah9
    @6Abdellah92 ай бұрын

    I watched abt 10 vids within the last hour I feel 10x smarter already

  • @git-amend

    @git-amend

    2 ай бұрын

    Awesome!

  • @oldshamen
    @oldshamen7 ай бұрын

    Great tutorial. In the interest of completeness, could you suggest how you build from a prefab instead of creating and setting up a gameobject from code (as suggested in one of the on-screen tips in the video)?

  • @git-amend

    @git-amend

    7 ай бұрын

    Sure - you could either pass in the prefab as part of the constructor, or in the final Build() method. Here is an example: public class Builder { GameObject enemyObject; public Builder(GameObject prefab) { enemyObject = GameObject.Instantiate(prefab); } public Builder WithName(string name) { enemyObject.name = name; return this; } public Builder WithHealth(int healthValue) { var healthComponent = enemyObject.GetOrAdd(); healthComponent.SetHealth(healthValue); return this; } public GameObject Build() { return enemyObject; } }

  • @kecia9988
    @kecia99882 ай бұрын

    Great video!, btw on 3:40 you wrote that we should consider initializing the Builder with a prefab but how is that done? what if your "Enemy" class is the prefab in question? Should I put the prefab as a parameter of the method Build()?

  • @git-amend

    @git-amend

    2 ай бұрын

    I would consider using a prefab if you have several components that are common to all of a particular type of thing, like an Enemy. So all Enemies might have the same mesh and colliders for example, and the prefab saves you having to create a new game object and set those for each one. You could pass a reference to that prefab as a parameter, and that way you only need to instantiate a version of that prefab with the additional settings you want set by the Builder. You could also have a factory that has references to many variations of Enemy prefabs that has a CreateEnemy() method - it might choose a prefab at random from a List, then use the Builder to do some additional configuration and return a ready to use Enemy.

  • @shadyleegamer
    @shadyleegamer6 күн бұрын

    How do you get to use the single line and multiline code prediction and completion in Rider?

  • @git-amend

    @git-amend

    6 күн бұрын

    There are 2 ways, and I have both but in the videos I use GitHub Copilot: github.com/features/copilot The other way is to use JetBrains AI Assistant: www.jetbrains.com/ai/ Both of these are paid plugins and cost $10/mo.

  • @stickguy9109
    @stickguy91099 ай бұрын

    I like this kinda videos. My code always suffers from excess spaghetti

  • @git-amend

    @git-amend

    9 ай бұрын

    Awesome! Using patterns can make a world of difference in your projects!

  • @ugurkarabulut8598
    @ugurkarabulut85987 ай бұрын

    Can you make a video about adapter pattern

  • @git-amend

    @git-amend

    7 ай бұрын

    Yes, I've got that on my to-do list!

  • @bhaktijpatil
    @bhaktijpatil2 ай бұрын

    I'm used to Java at work and follow most design patterns. But I'm really struggling to use them with Unity 3D. I'm trying to build a minecraft like block system for my game and can't quite figure out a way to do this in a way that's very extendible. For now I'm just trying to figure out a way to create 100s of blocks in a way that I have a base block with all the properties for ex: isFlammable, isTransparent, textures (6 for each face) but I'd like a way to select uniformMaterialSetup, distinctMaterialSetup, topDownSidesMaterialSetup, etc. And then I just create 100s of prefabs? And store it somewhere, or in a way that I can apply a block type to any baseblock and it gets all the properties. I've explored scriptableobjects, OOP mechanics and patterns so far. But even in my head I can't build a proper architecure I'm happy with. Most of my struggles come from how the inspector interacts with classes and mesh vs code. Your videos have helped a lot after trying a lot of things for a few days, but I'd appreciate a guideline for how I should start thinking about this. Thanks a lot for these videos.

  • @git-amend

    @git-amend

    2 ай бұрын

    Thanks for the comment. I wonder if the Flyweight pattern might help you out with the blocks. By separating intrinsic data (e.g., textures, flammability) from extrinsic state (e.g., position, specific material setups), you can create a base block type and then efficiently instantiate and manage variations through shared data structures. The Flyweight can reference your base prefab. Then maybe a Factory / Builder combination to create all kinds of variations?

  • @bhaktijpatil

    @bhaktijpatil

    2 ай бұрын

    @@git-amend wow, I just started reading about this as I've not used it ever before and what it intends to do aligns very closely with what I want. I understand that in the end I will end up using most common patterns, but this is exactly what I was struggling with. What should be the outermost pattern if that makes any sense. Thank you so much. I will read more about this and comment back when I make progress.

  • @git-amend

    @git-amend

    2 ай бұрын

    @@bhaktijpatil Sounds good. I also have a video called Flyweight Factory that does something like this. The video is about projectiles, but you could do something similar for blocks.

  • @octia2817
    @octia28179 ай бұрын

    Cool video, but some of the sound effects near the beginning were too loud.

  • @git-amend

    @git-amend

    9 ай бұрын

    Thanks for the feedback, I'll keep that in mind.

  • @Sworn973
    @Sworn9737 ай бұрын

    Meh, the only think I really don't like about the "fluent builder strategy" that is done here, is that you end up coping the entire object that you want to build, having the builder return itself is the way to go, but without making a clone of the target object. So you don't have to duplicate everything. Quick example is to just add a new property like "isActive", so you have the get/set for the actual class, and now you have to duplicate everything in the builder, a new isActive property with also its getter and setters.

  • @Cxdyy
    @Cxdyy9 ай бұрын

    Why you still using unity? Just curious

  • @git-amend

    @git-amend

    9 ай бұрын

    That's a good question, and a few people have asked if I will make a video about that - which I still need to decide. While I'm not happy about the actions of Unity management, I'm also not interested in watching it burn to the ground completely and potentially destroying the work of so many, especially those who make their living making tools for Unity. For the next few weeks at least, I'll focus on making videos that are more about software engineering principles, which are transferable to any modern programming language.

Келесі