you may have heard other programmers use the word encapsulation today we're going to talk about what it means why it's not the same as information hiding and how you can use it to improve your design before we dive in let's first talk about today's sponsor skillshare skillshare is an online learning community with thousands of inspiring classes for creators explore new skills deepen existing passions and get lost in creativity skillshare has many classes on web development programming in python software engineering and software design at the moment i'm following frank kane's course on data science and machine learning with python it's really comprehensive it contains lessons about statistics data types clustering algorithms decision trees covers libraries such as pandas basically everything you need to know in order to get started skillshare is curated for learning there are no ads and they're always launching new premium classes so you can stay focused and follow wherever your creativity takes you the first NUMBER_TOKEN of my subscribers to click the link in the description will get a one month free trial of skillshare so you can start exploring your creativity today there are two meanings of the word encapsulation the first is that we group things in a way that each group represents the essential features of something for example a culture document encapsulates a company's beliefs values and practices or a customer class represents all the data that we consider to be essential for representing a customer in our software system let's look at an example here i have an example of a very simple customer class now there's no way you would at the moment say that this actually encapsulates what a customer represents it has an id it has a name and an email address you might want to add lots of different fields to this customer class for example perhaps we want an address line NUMBER_TOKEN which is a string and we want an address line NUMBER_TOKEN as well and perhaps a zip let's call that postal code we're in europe after all city country and so on and so on you're going to reach a point where this list is going to be complete it's going to encapsulate everything that you want a customer to represent the second meaning of encapsulation is that it defines boundaries around things for example han solo was encapsulated in carbonite by jeff of the hot i still have nightmares about that by the way or you could be encapsulated in prison by the government for wire fraud so encapsulation in that sense is about restricting access in some way in code you can achieve that by making instance variables and methods private or protected even though python is a bit special in that regard because it doesn't allow you to actually restrict access concept that's related to encapsulation is information hiding it's not the same thing though with information hiding you hide certain aspects of your code to the outside you provide an interface a kind of a black box that other functions modules and classes use without having to know anything in particular about how it works internally for example let's say your software uses a payment or stripe you want to be able to do payment processing at various places in your code but you don't want that code to be dependent on stripe specific things so what do you do you hide the information you create a stripe payment processing module that contains functions for starting a payment processing refunds calculating tax percentages etc etc inside the module you have for the implementation details such as which
START_SPONSOR_TOKEN before we dive in let's first talk about today's sponsor skillshare skillshare is an online learning community with thousands of inspiring classes for creators explore new skills deepen existing passions and get lost in creativity skillshare has many classes on web development programming in python software engineering and software design at the moment i'm following frank kane's course on data science and machine learning with python it's really comprehensive it contains lessons about statistics data types clustering algorithms decision trees covers libraries such as pandas basically everything you need to know in order to get started skillshare is curated for learning there are no ads and they're always launching new premium classes so you can stay focused and follow wherever your creativity takes you the first NUMBER_TOKEN of my subscribers to click the link in the description will get a one month free trial of skillshare so you can start exploring your creativity today there END_SPONSOR_TOKEN