What Is Encapsulation And Information Hiding?

  Рет қаралды 28,536

ArjanCodes

ArjanCodes

Күн бұрын

The first 1,000 people to use this link will get a 1 month free trial of Skillshare: skl.sh/arjancodes01221.
In this video I explain what encapsulation and information hiding are (they're not the same thing!), and how they're related to software design.
💡 Get my FREE 7-step guide to help you consistently design great software: arjancodes.com/designguide.
💻 ArjanCodes Blog: www.arjancodes.com/blog
The code I worked on in this video is available here: github.com/ArjanCodes/2022-en....
🎓 Courses:
The Software Designer Mindset: www.arjancodes.com/mindset
The Software Designer Mindset Team Packages: www.arjancodes.com/sas
The Software Architect Mindset: Pre-register now! www.arjancodes.com/architect
Next Level Python: Become a Python Expert: www.arjancodes.com/next-level...
The 30-Day Design Challenge: www.arjancodes.com/30ddc
🛒 GEAR & RECOMMENDED BOOKS: kit.co/arjancodes.
💬 Discord: discord.arjan.codes
🐦Twitter: / arjancodes
🌍LinkedIn: / arjancodes
🕵Facebook: / arjancodes
👀 Code reviewers:
- Yoriz
- Ryan Laursen
- Sybren A. Stüvel
- Dale Hagglund
🎥 Video edited by Mark Bacskai: / bacskaimark
🔖 Chapters:
0:00 Intro
1:09 Encapsulation: first meaning
1:32 Encapsulation example
2:22 Encapsulation: second meaning
2:54 Information hiding
4:08 Encapsulation and information hiding example #1
7:16 Relation with design principles
8:30 Encapsulation and information hiding example #2
11:37 Final thoughts
#arjancodes #softwaredesign #python
DISCLAIMER - The links in this description might be affiliate links. If you purchase a product or service through one of those links, I may receive a small commission. There is no additional charge to you. Thanks for supporting my channel so I can continue to provide you with free content each week!

Пікірлер: 50
@ArjanCodes
@ArjanCodes 2 жыл бұрын
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 жыл бұрын
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.
@ArjanCodes
@ArjanCodes 2 жыл бұрын
Glad you enjoy it!
@adiladawi
@adiladawi 2 жыл бұрын
thanks for sharing knowlege, and being a mentor for us
@robertbrummayer4908
@robertbrummayer4908 2 жыл бұрын
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 жыл бұрын
Yep - making sure your function names are (almost) always verbs is good practice too.
@yogiwhy9531
@yogiwhy9531 2 жыл бұрын
Thanks Arjan! I would request about several ways implementing complex state machine (incl. substates).
@fastrockstar1705
@fastrockstar1705 2 жыл бұрын
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 жыл бұрын
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 жыл бұрын
I love the star wars reference :)
@ArjanCodes
@ArjanCodes 2 жыл бұрын
Couldn't resist :).
@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!
@CaptainCsaba
@CaptainCsaba 2 жыл бұрын
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 жыл бұрын
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.
@user-st5cy3ue5g
@user-st5cy3ue5g 2 жыл бұрын
God bless u. This is awesome. Thx a lot from QA engineer from Russia:)
@ArjanCodes
@ArjanCodes 2 жыл бұрын
Glad it was helpful!
@leliarubiano6392
@leliarubiano6392 Жыл бұрын
KZbin has to have a button of love it.
@enrique-zarate4594
@enrique-zarate4594 6 ай бұрын
This is so awesome.
@ArjanCodes
@ArjanCodes 6 ай бұрын
Glad you enjoyed the video, Enrique!
@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.
@stefanvanjaarsveld7589
@stefanvanjaarsveld7589 2 жыл бұрын
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 жыл бұрын
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.
@janez1010
@janez1010 2 жыл бұрын
Hello, another greate video! Can you recommend me a book that covers design principles in python? Thank you!
@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?
@MrGb666
@MrGb666 2 жыл бұрын
Haha, I loved the Han Solo encapsulation!
2 жыл бұрын
Would it be possible to define is_cancelled/is_paid as properties and cancel/pay as property setters? It that makes no sense?
@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
@blabla5534
@blabla5534 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.)
@queerstudbroalex
@queerstudbroalex Жыл бұрын
At first, I misread the title as (brackets for clarity) ""What is [encapsulation and information] hiding?"
@ArjanCodes
@ArjanCodes Жыл бұрын
Hahah No problem Kylie. I hope you liked the video!
@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 жыл бұрын
@@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."
@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).
Let's Take The Bridge Pattern To The Next Level
17:13
ArjanCodes
Рет қаралды 38 М.
7 Python Code Smells: Olfactory Offenses To Avoid At All Costs
22:10
They RUINED Everything! 😢
00:31
Carter Sharer
Рет қаралды 26 МЛН
Final muy inesperado 🥹
00:48
Juan De Dios Pantoja
Рет қаралды 12 МЛН
Как быстро замутить ЭлектроСамокат
00:59
ЖЕЛЕЗНЫЙ КОРОЛЬ
Рет қаралды 13 МЛН
Pong & Object Oriented Programming - Computerphile
12:51
Computerphile
Рет қаралды 262 М.
5 Tips To Achieve Low Coupling In Your Python Code
18:30
ArjanCodes
Рет қаралды 94 М.
You Can Do Really Cool Things With Functions In Python
19:47
ArjanCodes
Рет қаралды 216 М.
Unlocking your CPU cores in Python (multiprocessing)
12:16
mCoding
Рет қаралды 293 М.
Protocol Or ABC In Python - When to Use Which One?
23:45
ArjanCodes
Рет қаралды 197 М.
Fundamental Concepts of Object Oriented Programming
9:16
Computer Science
Рет қаралды 851 М.
The Power Of The Plugin Architecture In Python
24:06
ArjanCodes
Рет қаралды 110 М.
This Is Why Python Data Classes Are Awesome
22:19
ArjanCodes
Рет қаралды 791 М.
The Factory Pattern in Python // Separate Creation From Use
14:58
8 Python Coding Tips - From The Google Python Style Guide
17:12
ArjanCodes
Рет қаралды 153 М.