 So today we're going to be talking about encapsulation and the different ways it's done I do want to say first I have gone back to using Microsoft Office over Libre Office and one of the biggest reasons why is the quality of presentations in Libre Office is Terrible in my opinion. There's a lot of control That you really lose out on Like if you go back and watch the very first presentations I did Even though it was a rather simple little thing it adds a bit of It adds a bit to the experience to see things like each letter fade in a little bit a bit more like it's being read Instead of just immediately coming up or very quickly the whole thing fading in You know games go Not so much nowadays that there's so much voice acting, but I grew up with games that did that kind of thing as being heralded because it just adds to the experience But there's there was other things issues with the workflow or how things were ridiculously slow I'd hit a button and it wouldn't go right away, but so so we're we're back But yeah encapsulation the different ways it's done I do need to say in this in this video the definitions are for everything are going to be quite a bit Less strict than in the other videos say like on object oriented under what data types are just because there aren't anywhere near as good formal definitions for the different types of encapsulation and so We're speaking very generally in this one. So that's for different practices for structuring the encapsulations for here, we're going to call all of them just like project or module or Whatever, we're not going to get into the specifics. I just want to show some different approaches to the hierarchies Because that's the point of encapsulation is structuring your code So one of the both one of the popular practices is a flat Well, just just a flat set of namespaces or packages or modules or whatever Python is one of the languages that definitely encourages this although there's numerous others JavaScript seems to Well, it gets a bit funky when you start delving and do what type script does but JavaScript seems to be pretty flat as well The idea with this is that it generally requires less typing Uh, that you can you know, you can just type out the single thing that you're interested in And then it'll just be there after that point instead of messing around with r.i. Where is it in this tree? another structure And then you'll see with java. Yeah, java is org in this case literally or g Not the organization, but or g dot and then the company name and then the project name and then the module name uh I find this Ridiculously verbose. However, it does it does definitely provide a tremendous amount of structure to the overall To the overall hierarchy Now there is a similar approach to this which it winds up very structured But just takes away the org part I have this one animated slightly wrong apparently. Okay. That was the end of it. Um It takes away the org part and just has it with the company dot whatever the project name is dot whatever the module name is Uh, you see this with like the dot net libraries um Third party idle libraries tend to be structured like this Uh, although what I do is slightly different for for my Generally for my idle libraries if they're meant to be reused by general masses I I they're they look a bit different than this, but if there's something that I do um If there's something that I do for just personal Things that aren't going to be released to the masses then they are structured pretty similarly to this But then what do I think of all of it? How do I Go about it most of the time? well, it completely Depends I'm I don't think there's any one single right way to approach this kind of stuff Your only concern should be making sure that anything that should logically be grouped together is And that things aren't Intidious hierarchies I guess just make sure the structure makes sense And after that point you're just good. It's not like one approach is better than the other We're literally talking about just different ways to structure things, but I have seen Way more programmers than I'd like to admit Go at each other over how to structure this stuff appropriately and It doesn't change the way the code works. We're literally talking about organization Not anything to do with the code at all But then the forms of the encapsulation Generally speaking encapsulation exists to organize similar features together And this does wind up aiding in IntelliSense or auto completion, whichever you call it Some people consider them slightly different things, but they're often used interchangeably And also used to avoid naming conflicts. This is especially important where you have functions or Values especially with identical names, even though they have completely different intent This is especially important in Um Well like cc projects are notorious for this where Variable somewhere will literally just be named a single letter And if that letter exists within the same scope somewhere else Such as the top-level scope of a file And you include another file with that same value Fun times Fun times But namescape name name spacing Of any kind Any form of encapsulation will help Deal with those issues So then first we have the namespace right now again I am speaking very generally as for the definitions of these. I have seen The same Concept The same word for the concept be used in different ways in different languages So these are general But the namespace Largely to encapsulate other forms of encapsulation although there are certain instances where you will have like just a value At the at the namespace level instead of inside of a class or whatever you might have going on and Again, generally namespaces group things based on subject Although you will still often see top-level namespaces which group based on like a company or a project To use the dot net libraries as an example because they call them all namespaces You have the dot net stuff Mostly system dot whatever But then some specific stuff is separated into Microsoft dot and then its own little hierarchy Those are things that make sense to use on Microsoft's products, but might not make sense to use on mono or I can't think of any of the other dot net runtimes because they kind of don't really work well But you know the Microsoft hierarchy the the you know the Top namespace Microsoft and then everything underneath it You would not expect to run under mono. You expect that to run under dot net and so You typically using these two group on subjects. So you might have mathematics dot and then of everything that got would be part of mathematics gets put under there Or containers this is how I at least at the top level how I usually go about things but it's namespaces exist just to group things Based on similar feature not like tightcoupling, but just kind of These should all be in the same bag Modules are one of those things that I see a huge discrepancy in what everybody considers it specifically But it is it is a form of encapsulation and it generally at least from what I've seen encapsulates specific tasks things like visual basic net and other stuff really Really mess with that definition though. So again, this is very general But much like the namespace it just contains a bunch of whatever And I usually see again that this groups based on the task So when you had a namespace before of say, well, we'll use my own libraries as an example if you know, those are those are packages, but Using these definitions you could call like mathematics dot arrays The mathematics and the mathematics dot arrays would both be namespaces But something like mathematics dot arrays dot i o the i o Stuff would be a module for mathematics dot arrays The class is something that you specifically see in certain object oriented languages if you want to get into the Different ways of doing object orientation and how to encapsulate that stuff I have a video out already for object oriented programming Check that out but the class specifically Groups the entirety of an object together all of the values within the object And all of the methods that would be present For that object that are dispatching upon that object Any functions that may accept that object as a parameter that are declared outside of the class are going to be non dispatching and would act upon the object as if it be instantiated class As if it were As if it were any other value instead of being dispatching And classes can't contain other classes exactly why you would do that is Not a subject for this video But know that in most class based languages there is a possibility of defining a class within another class And so yeah because it's a concept very specific to object oriented programming it groups Objects basically everything relevant to that object Non class based object oriented languages have less obvious grouping Itas approach Requires a rather good understanding of the language itself to tell whether a function is dispatching or not And prototyping languages Uh Which some people might consider object based and not object oriented Are Tricky basically all grouping goes completely out the window So classes can be thought of as highly structured highly encapsulated object oriented programming so then we have the package and like Like the namespace and module this is something that doesn't really have any good specific definition uh but The package seems to be the most general of all of them In that it can contain values and procedures and functions and records and other packages It can act literally just as a namespace or it can add certain tasks specific stuff to something else Or it can even act as a singleton Which makes it somewhat similar to classes that follow the singleton pattern And so as a result it groups on abstract concepts I've never seen a language that had packages and any of this other stuff Packages are just sort of at least as I've usually seen them just catch all for grouping anything It's how you group things that decide what it would be in another language But then functional programming introduces something unique to encapsulation known as the closure This The concept of a closure largely exists to do something else however the closure can provide encapsulation This is important in languages like javascript where I believe acma script 6 remedied this a bit but prior to that there were not a concept of namespaces or encapsulation other than records and classes Well, not not classes because Javascript doesn't have classes. It's a prototype language, but um The way scope works in javascript can be a bit tricky and so closures would sometimes be used to provide Encapsulation in javascript since it's Sort of didn't have it before Javascript weird But if you use something like like type script When you use a namespace The namespace keyword in type script What that compiles down to if you're targeting say acma script 5 is Actually going to be a closure And so like I said in certain languages like javascript, but there are others it can be used something like a namespace It has like I said though it has plenty of other uses So it's not just limited to that every time you see a closure does not mean it's being used for encapsulation There's something to think about The purpose of software engineering is to control complexity not to create it Dr. Pamela I may be butchering this. I'm sorry, but xive And I'm quoting myself deal with it. I have an example here from one of the libraries you said you've used and This one i'm hiding the company name, but it's org.company.companysorter.companysort.sorter.sort.call You really need me to explain more about why I dislike java programmers I may get some flak for that That's definitely not all java programmers, but I've only seen that level of ridiculousness in the hierarchy of Encapsulation in java I've never seen anything even close to that in any other language and it was And I've seen that Way more than once in java I we've got to be up to about 30 times now But if you found this video helpful, please give me a thumbs up if you like what I do in general Please consider subscribing. It helps me out quite a bit and you get notifications when I make a new video No way you get the little number down in the sidebar There's a notification bell. You can also hit for the notifications. That's why it's a bell Also, since I haven't mentioned it in a while, I do have a patreon Consider becoming a patron It helps me make videos like this and the scientific lit reviews and other stuff that I do Now have a good one