Composition Over Inheritance - OOP in Roblox Studio

Поділитися
Вставка
  • Опубліковано 27 лис 2024

КОМЕНТАРІ • 68

  • @Immow
    @Immow 3 роки тому +32

    Hi, I don't use Roblox but Love2d but this is by far the best video I found about OOP. I was looking into inheritance but this video just makes it crystal clear that this is far superior. Thank you so much for taking the time to make this.

    • @BRicey
      @BRicey  3 роки тому +12

      That is absolutely amazing! Your very welcome! I'm glad I can get to people who are not only using roblox, but other engines

    • @tomsterbg8130
      @tomsterbg8130 6 місяців тому +2

      Yep, the fact that the mentality was explained really set me on my place. It's absolutely amazing to think of inheritance of "this is this" and composition of "this has this". Just the way of thinking is completely clear and you can see that it's superior. A human is an animal? Why don't we act dumb then. A human has animal features. This makes much more sense.

  • @Jason-xl8fm
    @Jason-xl8fm 3 роки тому +16

    Thanks for this video, been learning how to use OOP programming recently and it can get quite messy with the functions. Really nice to see someone who provides tutorials using OOP since it's really a great way to clean up your code.

  • @jasonmckay2769
    @jasonmckay2769 3 роки тому +8

    Simply explained. Great example as opposed to abstract concepts. Well done!

  • @tomsterbg8130
    @tomsterbg8130 6 місяців тому +2

    I love this I love this I love this!!!
    I've just seen how Packages work and I know how Godot works so my mentality would be more like "let's use packages to construct classes instead". I want to be more visual about it instead of core-based because code requires you to read it. I want to see my structure. Anyway both your method and mine should be able to achieve the same goals - composition where by changing the components you change code everywhere.
    I find it much easier to understand less abstract concepts and ideas like having composition out of actual components and using them as if they are default Roblox instance classes.

  • @planeman4453
    @planeman4453 2 роки тому +1

    dude, this is exactly what i was looking for! Inheritance is quite limiting and composition looks so much better. Stumbled upon this from devforum, great video!

  • @vashthestampede9999
    @vashthestampede9999 3 роки тому +2

    I asked for a video on composition last year and you finally did it, just wanna say great video and I really appreciate it.

  • @edrictigerist
    @edrictigerist 22 дні тому

    Composition Sounds super cool! Glad i stumbled onto this video : D

  • @rakha8812
    @rakha8812 3 роки тому +1

    This is why the Knit's Component Module is so awesome

  • @Roxaro
    @Roxaro 2 роки тому

    other OOP tutorials was boring but this something else

  • @wav8518
    @wav8518 9 місяців тому +1

    B Ricey i love your content, after watching and learning your OOP series, what should we learn or do next?
    I feel stuck and honestly i dont know what to do.

  • @danil-old-web
    @danil-old-web 3 роки тому +1

    This is the knowledge we hunger for!

  • @eliteengineer7340
    @eliteengineer7340 Рік тому

    you always have what im looking for , you are amazing

  • @karlmarx2704
    @karlmarx2704 3 роки тому +11

    Creating Classes with other Classes you say?
    Hmmmmmmmm...

    • @BRicey
      @BRicey  3 роки тому +1

      I just noticed your name lol

  • @He_ze
    @He_ze 10 місяців тому

    old videos, but timeless content lol. Currently in the process of cleaning up the code of my old game and this video was very useful

    • @BRicey
      @BRicey  10 місяців тому

      Glad I could help!

  • @vineetsawant9074
    @vineetsawant9074 Рік тому

    great example of how to implement OOP in Roblox!

  • @pm_see
    @pm_see 2 роки тому

    because of you I learned how to use Metatables in module scripts. Thanks B Ricey!!

    • @BRicey
      @BRicey  2 роки тому

      Glad I could help!

  • @bryceblazegamingyt9741
    @bryceblazegamingyt9741 2 роки тому

    I would love to see an updated oop video on metatables and modulescripts! And I want to see your new practices because I'm starting to get interested in Roblox development again because I never knew that Roblox was powerful enough to make abstract classes. Love your work

  • @Relphy
    @Relphy 3 роки тому

    HAPPY 2K SUBSCRIBERS!

  • @PixelKingStudios
    @PixelKingStudios 3 роки тому

    Nice video! Very informative 😄

  • @jotanews1776
    @jotanews1776 3 роки тому +2

    i fucking love you homie

  • @nlaps
    @nlaps 3 роки тому

    Great vid! I'm trying to get my habbit into OOP.

  • @fusion.studioX
    @fusion.studioX 25 днів тому

    so composition is just a bunch of little inheritances

  • @wifinoob3083
    @wifinoob3083 3 роки тому +1

    Love your videos.

  • @chillblox8
    @chillblox8 3 роки тому

    holy crap thanku i lov this method

  • @GaLzZy.
    @GaLzZy. 11 місяців тому

    it is kinda sad that there a no intellisense with OOP approaches in roblox studio :(

  • @yarik_superpro
    @yarik_superpro Рік тому

    this still very confusing to me,why it overrides itself if i make 2 of them!?Isnt this whole point of OOP!?

  • @menoitius5587
    @menoitius5587 Рік тому

    AWESOME tutorial

  • @pfever
    @pfever 5 місяців тому

    Downside of composition, you need to make tons of simple classes

  • @axelmonogatari3175
    @axelmonogatari3175 2 роки тому +3

    Its cool ... but
    DONT, by any means use ALWAYS composition. There are cases where it doesn't make sense and make you create lots of unnecessary modules. First check if TypeB is a TypeA (B can do all the things that A can, and can be replaced.), if not, then just extract in modules the things that you need from TypeA into TypeB.
    Also, you can use Both, and that's what I usually do a lot. For example:
    Vehicle (atributes: Name, color, speed, size) [methods: Move()]
    Car is a Vehicle(atributes: Engine, Wheels)
    Engine (Atributes: Capacity) [Methods: TurnOn(), TurnOff()]
    Wheel (Atributes: Color, size)
    Wings (Atributes: Color, size)
    Plane is a Vehicle(atributes: Engine, Wings)
    Bycicle is a Vehicle (Atributes: Wheels)
    In this example Vehicle is just an interface or an abstract class but the idea is that it can be upgraded with more unique methods that all vehicles will share.

  • @kidthatcries
    @kidthatcries 3 роки тому

    Awesome video. Just one question, is there a way to use self object on the base table? Something like this: setmetatable({ using self in this table }, metatable) on the new method

    • @BRicey
      @BRicey  3 роки тому +1

      Sadly, you can't. The workaround is using: local self = setmetatable({}, mt), and then in a line below saying: self.Model = self:MakeModel() or something

    • @kidthatcries
      @kidthatcries 3 роки тому

      @@BRicey thanks I'm gonna try that

  • @hello-uw2qw
    @hello-uw2qw Рік тому

    Great video! This has helped me understand OOP in a way that no other tutorials could. A question I have, however, is how I would apply this in a practical approach. Let's say I want the car to move forwards when I press 'W', using a LinearVelocity. The thing I am stuck on is:
    - Detecting key presses is done on the client, so how would I call the server method of 'Drive()' on the client, when you can't pass metatables through a remote event, and sending a remote event from Client > Server isn't viable, as I would be using RunService to detect when W is held, and then increase the speed the longer it is held, and obviously sending a remote event 60 times a second is not good
    Obviously I am not asking you to write the code for me, but an explanation of how I could go about this would be greatly appreicated.
    Either way, thank you for the great video!

    • @BRicey
      @BRicey  Рік тому

      You could just use a proxy method, something on the server that receives the remote event and then runs the appropriate method on the class

    • @hello-uw2qw
      @hello-uw2qw Рік тому

      @BRicey That's gonna cause loads of lag firing it 60 times a second, it needs to be done on the client. Atm I just don't use OOP for the client, and tbf it works fine but if I want to expand the code base its gonna be difficult

    • @BRicey
      @BRicey  Рік тому

      Yeah I wouldn’t fire it every second, only fire it for when it changes direction

    • @hello-uw2qw
      @hello-uw2qw Рік тому

      @@BRicey i think changing it on the client is the best approach, due to the fact that tye client has network ownership so it would be lag free

    • @BRicey
      @BRicey  Рік тому

      @@hello-uw2qw yeah

  • @each1teach1
    @each1teach1 2 роки тому

    Thanks

  • @exotic9345
    @exotic9345 3 роки тому

    Can you make an on screen coordinates system?

  • @ftgodlygoose4718
    @ftgodlygoose4718 3 роки тому

    Great video, it really helped me understand. Now all I have to do, is re-code my game from scratch using OOP lol

    • @BRicey
      @BRicey  3 роки тому

      just try to integrate your codebase in the future with OOP, I wouldn't rewrite your game rn

  • @Ryan-ww7un
    @Ryan-ww7un 2 роки тому

    I see someone watches Arjan Codes :)

  • @speedyg2295
    @speedyg2295 7 місяців тому

    I am using your method to. create apples. But i keep getting new is not a valid member of ModuleScript "ServerScriptService.AppleModScript" - Server - appleTrigScript:2. Which coming from the SSS script called appleTrigScript on line 2 which is only 3 lines: local Apple = script.Parent.AppleModScript
    local A = Apple.new(workspace.farmQuestModel.AppleModel)
    A:Drive()
    Now of course the apple is not going to drive and have tires. But i put in the CFrame to move it there. But i cannot get past the not a valid member of the apple mod script which is put together just like Car in your video. where there is a: function Apple.new(appleModel). Any ideas

    • @speedyg2295
      @speedyg2295 7 місяців тому

      Found it. I was not using Require in statement above

  • @Thzyr
    @Thzyr 3 роки тому +1

    Can you make another perlin noise vid cuz its outdated

    • @BRicey
      @BRicey  3 роки тому

      What do u mean? I don’t think the api has changed.

    • @Thzyr
      @Thzyr 3 роки тому

      @@BRicey maybe try doing the script again i think i got something wrong

  • @Revoltition
    @Revoltition Рік тому +1

    can you please explain it further for me?
    i get how it works but i don't really get why you would need to use it and in what cases should you do so

  • @Mr1Lito
    @Mr1Lito 2 місяці тому

    13:01 i keep getting this error: attempt to index nil with 'IsFlat', why?

    • @Mr1Lito
      @Mr1Lito 2 місяці тому

      it works now but i have no idea why, i asked chatgpt for help and it gave me a code to copy and paste (it was the exact same as mine) but now it worked

    • @Passsoio
      @Passsoio 28 днів тому

      I have the same problem, for some reason the values of the tables are printing nil

  • @audrete6071
    @audrete6071 3 роки тому

    How do you loop through a string? Like a for loop but instead of looping through a table it loops through a string

    • @BRicey
      @BRicey  3 роки тому +4

      for i = 1, string.len(yourString) do
      local char = string.char(i) -- do whatever you want with it.
      end

    • @audrete6071
      @audrete6071 3 роки тому

      @@BRicey thank you

  • @gabrielhallai9905
    @gabrielhallai9905 2 роки тому

    Hello hello

  • @eduardomattos1561
    @eduardomattos1561 3 роки тому

    Chunk minecraft in roblox plss ;c

  • @niklase.h.jensen2209
    @niklase.h.jensen2209 3 роки тому

    B ricey do you know how to make tank? If you do please tell me

    • @BRicey
      @BRicey  3 роки тому

      I made a crappy one in the past but I’ll do a tutorial on one in the future

    • @niklase.h.jensen2209
      @niklase.h.jensen2209 3 роки тому

      Thank you

  • @goose13378
    @goose13378 4 місяці тому

    Tack!

  • @my_beautifulnoob2889
    @my_beautifulnoob2889 3 роки тому

    E