What Is Encapsulation And Information Hiding?

Поделиться
HTML-код
  • Опубликовано: 25 дек 2024

Комментарии • 51

  • @ArjanCodes
    @ArjanCodes  2 года назад +5

    The first 1,000 people to use this link will get a 1 month free trial of Skillshare: skl.sh/arjancodes01221.

    • @sbrugby1
      @sbrugby1 2 года назад

      It just feels wrong seeing python in vscode and and not seeing it colored with an explosion of semantic highlighting.

    • @iklintsov
      @iklintsov 2 года назад

      Cannot get a free trial without entering credit card details. :(

  • @beckaddison5827
    @beckaddison5827 2 года назад +18

    I love how you're able to make content both informative without being too long! your instincts on project architecture are really helpful and easy to learn from.

  • @adiladawi
    @adiladawi 2 года назад +1

    thanks for sharing knowlege, and being a mentor for us

  • @robertbrummayer4908
    @robertbrummayer4908 2 года назад +3

    Great video, Arjan. I love the great names used in the Order class. For instance, is_cancelled is a great example as it already tells the user that the result is a boolen. Using such intention revelaing names allows one to read code almost like written English sentences which is great for readability. I also like how the Order class demonstrates information hiding. Best wishes to the Netherlands from Austria :)

    • @scleralp
      @scleralp 2 года назад +1

      Yep - making sure your function names are (almost) always verbs is good practice too.

  • @fastrockstar1705
    @fastrockstar1705 2 года назад +9

    Great video as always!
    I would really love how your Git/project management process is. My small team and me always struggle with that.
    How do we handle branches. How much do we edit/add per branch. How to structure commits and so on.
    Stay healthy and a happy new year ;)

    • @ArjanCodes
      @ArjanCodes  2 года назад +4

      Good suggestion, thanks!

    • @theninjascientist689
      @theninjascientist689 2 года назад

      @@ArjanCodes I'd love that too! I'm only using git to learn the ins and outs of it but at the same time I have these exact same questions!

  • @robertbrummayer4908
    @robertbrummayer4908 2 года назад +4

    I love the star wars reference :)

  • @ИльяФилимонов-ч5ъ
    @ИльяФилимонов-ч5ъ 2 года назад

    God bless u. This is awesome.
    Thx a lot from QA engineer from Russia:)

  • @leliarubiano6392
    @leliarubiano6392 Год назад

    RUclips has to have a button of love it.

  • @CaptainCsaba
    @CaptainCsaba 2 года назад +1

    Awesome video as always! Polymorphism is the one that still gives me headaches with Python. Would love a video on it in the future.

    • @18something
      @18something 2 года назад

      Not easy to implement in python, you will need to overload the class methods

    • @dawidp749
      @dawidp749 2 года назад

      @@18something I thnik you are wrong. It is simple and easy and is being use all the time. Even when you use for loop on any iterator ex. tuple, list it is polymorphism.

    • @pranavnyavanandi9710
      @pranavnyavanandi9710 2 года назад +1

      There are four types of polymorphism in python:
      1. Duck typing
      2. Method overriding
      3. Method overloading
      4. Operator overloading

  • @musicologyman
    @musicologyman 2 года назад

    Whew! I saw Arjan’s picture and then I saw a word in the title that my brain initially (mis)recognized as “emasculation” an’ I’m like, “Okay, Arjan, this better be good!” And then I looked at the title again.

  • @isolatedsushi5996
    @isolatedsushi5996 2 года назад

    Lol, I watched a few of your videos from time to time. Only just realised that you were my professor a few years back!

  • @coderider3022
    @coderider3022 2 года назад

    My python is like my SOLID c#, glad I found this channel which sort of promotes more practices which are timeless (to a point) and apply to most languages. Main python guy at my place thinks pattern defeat the point of using python and regularly considers abstractions code debt ! Wtf.

  • @yogiwhy9531
    @yogiwhy9531 2 года назад

    Thanks Arjan! I would request about several ways implementing complex state machine (incl. substates).

  • @enrique-zarate4594
    @enrique-zarate4594 Год назад

    This is so awesome.

    • @ArjanCodes
      @ArjanCodes  Год назад

      Glad you enjoyed the video, Enrique!

  • @MrGb666
    @MrGb666 2 года назад

    Haha, I loved the Han Solo encapsulation!

  • @stefanvanjaarsveld7589
    @stefanvanjaarsveld7589 2 года назад +4

    In your opinion, should you use normal get and set methods in python, like the standard java way "get_name()". Or should you use the property() method or @property decorator as a more "pythonic" solution?

    • @ArjanCodes
      @ArjanCodes  2 года назад +9

      I like the property syntax a lot in Python, so I will generally use that instead of get_xxx and set_xxx methods. I think getters and setters are still useful, especially if the computation to be done is more complex. I tend to restrict using properties to things that are easily computed.

    • @stefanvanjaarsveld7589
      @stefanvanjaarsveld7589 2 года назад

      @@ArjanCodes That makes sense. Thanks for the reply! I really enjoy your videos, always very informative.

  • @siddsp02
    @siddsp02 2 года назад

    Python does allow you to restrict access. That's what __setattr__ and __getattribute__ do. You can also ensure that an object's variable doesn't get its access modified in an unintended manner by using metaclasses or having the parent class' attibute assignment overloaded so the super() call can't allow for an unintended mutation.
    For more complicated encapsulation, you can also use descriptors, which control how they themselves are accessed and modified when assigned a variable to a class.

    • @pranavnyavanandi9710
      @pranavnyavanandi9710 2 года назад

      I have not understood descriptors till know. I read that they are what make quite a few things happen in python.

    • @aflous
      @aflous Год назад

      @@pranavnyavanandi9710 this + reflections

  •  2 года назад

    Would it be possible to define is_cancelled/is_paid as properties and cancel/pay as property setters? It that makes no sense?

  • @SyedAshrafulla
    @SyedAshrafulla 2 года назад

    Based on the contrived example, attempts to hide information without encapsulation seem to only occur as hacks (in the case given, I could imagine that code existing as part of a migration). Is that right?

  • @janez1010
    @janez1010 2 года назад

    Hello, another greate video! Can you recommend me a book that covers design principles in python? Thank you!

  • @blabla5534
    @blabla5534 2 года назад +2

    Hey Arjan, what are your thoughts on protected and private methods, variables, constants, etc on the *module* level? (for importable modules)

    • @blabla5534
      @blabla5534 2 года назад

      (if I follow the same rules consistently, I feel my code gets littered with underscores.)

  • @thomasburette9129
    @thomasburette9129 2 года назад

    Another way to look at this is that when you create a new class, you use information hiding to make the distinction between the public interface and the private implementation.
    When we design a new class we encapsulate together several elements. The encapsulated elements that are NOT hidden become the public interface. The elements on which you apply information hiding are not part of the interface, they become the implementation (Some would say the are private interface).

  • @pavelbilek6955
    @pavelbilek6955 Месяц назад

    Have the same glasses at home... coincidence?

  • @voxelfusion9894
    @voxelfusion9894 2 года назад

    Is there a way to enforce it in python, other than essentially placing hints in the name? An IDE will surely give a warning when encapsulation is broken, but this isn't like C++ where the compiler enforces capsule integrity.

    • @robertbrummayer4908
      @robertbrummayer4908 2 года назад

      You can use a linter such as Pylint to detect access violations

    • @juniorceccon
      @juniorceccon 2 года назад

      Unfortunately, there isn't. There are some ways to make it harder for the lib user, making them going through some hoops to direct access it. But effectively enforce that, not. At least not on the lib developer side. If an user is using internal code when they are not suppose to, and you update breaking the internal api, all the places that they are using it is going to break, and that's on them.

    • @18something
      @18something 2 года назад

      The __ means private and is hidden. You cant access that atribute

    • @juniorceccon
      @juniorceccon 2 года назад +1

      @@18something python changes the name, you can still access it. The name becomes _ClassName__member. That just make it obvious that you should not be accessing it. It is on the dev, which is using the lib, to be responsible and not use it.

    • @firstname4337
      @firstname4337 2 года назад

      @@juniorceccon yo mean "fortunately, there isn't."