Object-oriented concepts. Understanding object-oriented concepts: Encapsulation. Although there are many languages that support some form of object orientation with many different syntaxes, all true object-oriented languages must provide support in some manner for these three concepts. Encapsulation, inheritance, and polymorphism. This lesson will review encapsulation. Here's a definition, but the gist of it is that encapsulation means that the details are hidden inside the object and only an interface is exposed. Languages will differ on how and how well that encapsulation is enforced. Encapsulation means that data is not directly accessible to other classes. In Python, we would generally use properties to expose an interface, as we'll see in the demo. In Java, we would use the JavaBeans specification setter and getter pattern. Again, other languages will provide their own means, such as the get and set that's in TypeScript. One of the benefits of encapsulation is that we're free to change the internals of a class. So long as the interface does not change, client code would be unaffected. By eliminating direct dependencies on the implementation, we're free to change that implementation. We've eliminated direct dependencies, giving ourselves looser coupling and more freedom. Encapsulation prevents direct manipulation. Again, depending on different languages how strongly that's enforced. But the concept is that only by sending messages that select methods from the interface, are we able to interact with objects? This is the idea illustrated. Data and the code of methods is hidden. Only the interface is visible and touchable by outside code. Encapsulation provides two different kinds of protection. An object's internal state is not visible to outside code, the client code, and cannot be corrupted. For example, we might want to prevent client code from setting a name, some property called Name, like a for person, to anything other than a string. If we allow direct manipulation, that might not be preventable. But if direct manipulation is prevented, how does access work? By providing accessor on mutator methods, getters and setters. In Python, for example, client code will be written as if it were directly reading or assigning to the attribute. But in reality, Python is going to convert those accesses to calls to a getter or setter method transparently. Java, on the other hand, doesn't have that degree of transparency. There's no special language support for that capability. Instead, there's an explicit naming convention from the JavaBeans specification their programmers must use consistently, and other languages will have their own way of doing things. For example, TypeScript and the latest versions of ECMAScript, it's going to be getter and setter methods with similar transparency to what we've seen in Python. In Smalltalk, one instance of a class can't touch the data, even of another instance of the same class, most of our languages are not that locked up. For example, in Java, the code for a class can access the data in any instance of that class. Whereas in Smalltalk, it can't, only via the interface. Now honestly, when I write my code in Java, or in Python, or any other language, I pretend as if it is Smalltalk. In fact, I pretend as if it's even more than that. Only my getter and setter methods will talk directly to the data. No other method will talk directly to the data other than my getters and setters. That's how I write that code, and I will show that in the demonstration. But the point is, we only use the interface to manipulate the objects state. In our next video, we will look at demonstration of encapsulation, and exactly what I mean by limiting the use of the actual internal data just to this setter and getter methods.