no! Scaling is very hard. Especially in a system like this. Almost no comments in the code. If it’s not readable as code you redo it. Very pragmatic programming style. At this scale you don’t follow the rules.
no! Scaling is very hard. Especially in a system like this. Almost no comments in the code. If it’s not readable as code you redo it. Very pragmatic programming style. At this scale you don’t follow the rules. There is no book called “How to deal with all the users in the world at the same time”
of far far away, the idea of software was much simpler. You had data. You had functions. The functions modified the data and returned new data. End of story.
programming or structured programming (depending how you look at it). But as software complexity grows, this style of programming can grow out of hand, very fast.
programming or structured programming (depending how you look at it). But as software complexity grows, this style of programming can grow out of hand, very fast. There is no sense of structure (hah) and over time it gets difficult to get work done.
back to the 50s, it’s not until around 1965 when the a lot of the common concepts of OOP appear in the language Simula. These concepts influenced some languages but it wasn’t until the mid 1980 when language designers started to take notice. C++, Objective- and Eiffel were one of the first ones.
back to the 50s, it’s not until around 1965 when the a lot of the common concepts of OOP appear in the language Simula. These concepts influenced some languages but it wasn’t until the mid 1980 when language designers started to take notice. C++, Objective- and Eiffel were one of the first ones. And in the 90s OOP became the tour de force in languages like Java.
is the point? OOP is usually defined by three concepts. Which I will try to explain, and then show with examples how they benefit you. But first. Let’s talk about OOP generally.
by classes (or structures). Classes are ways to group together functions and variables. To create an object, we create a variable that is of the Class’s type.
by classes (or structures). Classes are ways to group together functions and variables. To create an object, we create a variable that is of the Class’s type. But even with this simple idea, we gain a lot of power.
once, at the initialization of an object. An object is fully formed when a constructor has finished running. They have no name and cannot be called directly.
called when the lifetime of an object ends.” “The purpose of the destructor is to free the resources that the object may have acquired during its lifetime.”
responsibility” or “A class should have only one reason to change” Animal shouldn’t be responsible for Eat(); and GrassGrow(); that is just going to make it increasingly harder to use and maintain.
variables from a parent class. The child class is considered a subtype of the parent class. This is a way to extend the functionality of the parent class and creates a certain kind of hierarchy.
then objects of type T may be replaced with objects of type S” In our case. If you need an Animal, you can use a Cat or a FoxHound, they both 100% work as Animals.
then objects of type T may be replaced with objects of type S” In our case. If you need an Animal, you can use a Cat or a FoxHound, they both 100% work as Animals. But if you need a Cat, you can’t use a FoxHound.
initializing the class Animal, the compiler will allocate memory for an Animal. In our case, it will allocate for the integer stored within animal. When trying to store a Dog in the memory space allocated for Animal, then there isn’t enough space for barkCount.
initializing the class Animal, the compiler will allocate memory for an Animal. In our case, it will allocate for the integer stored within animal. When trying to store a Dog in the memory space allocated for Animal, then there isn’t enough space for barkCount. This is called Slicing
initializing the class Animal, the compiler will allocate memory for an Animal. In our case, it will allocate for the integer stored within animal. When trying to store a Dog in the memory space allocated for Animal, then there isn’t enough space for barkCount. This is called Slicing The vector is storing memory for Animal. Nothing more.
vector a pointer to Animal (either raw/unique/shared), then the actual memory stored within the vector is a pointer. A pointer can’t slice because they are always of the same size.
vector a pointer to Animal (either raw/unique/shared), then the actual memory stored within the vector is a pointer. A pointer can’t slice because they are always of the same size. If you then allocate memory on the heap for a Dog but store it in a Animal pointer, no slicing will occur. Because you explicitly allocated memory for a Dog on the heap but point to it.
eat. But they eat so much, and they slobber all over. I like how all Animals have an Eat(); function and it’s useful to have one function you can call. But I need a way to change how Eat(); is implemented, but only for Dogs.
open for extension, but closed for modification" Here we have done this in two ways. Once with inheritance and in another way with overriding virtual functions.
with no virtual functions. When that class is allocated on the stack, only the member variables are allocated to that stack. So when someone calls a function, it’s almost like someone is calling a freestanding function.
function in your class a different thing happens. A pointer to a virtual function table is allocated. This pointer is used when calling virtual functions.
function in your class a different thing happens. A pointer to a virtual function table is allocated. This pointer is used when calling virtual functions. When a class of type Animal is created, the virtual function entry for Eat(); points to the Animal version of Eat. And when you allocate for Dog, it points to the Dog implementation of Eat
used but against many different objects. In the example we just did, we were able to use the interface of Animal but the underlying object could be a Dog without us ever knowing it.
against the real world. It actually doesn’t make sense to create an animal by itself. It always has to be a certain kind of animal. This can be solved by creating an Abstract Class or what is often called an Interface.
not work to create a variable of the type Animal. This is because there has been no implementation of the function Eat(); and any derived class has to implement that function if they want to be usable.
In the last example the user was able to refer to the numberOfMeals variable directly. He could even change it if he wanted. If that is our design, then fine. But this can cause someone to write code that changes the state of our class to something invalid.
They apply to functions and variables (any member of the class). public: Anyone can access the member. Same as we had before. protected: Only accessible inside of Base and Derived classes. Not publically.
They apply to functions and variables (any member of the class). public: Anyone can access the member. Same as we had before. protected: Only accessible inside of Base and Derived classes. Not publically. private: Only accessible inside of Base. Not derived classes and not publically.
towards classes that are then enjoyable to use correctly and hard to use incorrectly. Also. The only difference between struct and class is that a struct is by default public and a class is by default private. There is no other difference between them.
of the object's components.” Encapsulation is often called an “information hiding mechanism” where the user of the system is not aware of the underlying complexity but can still use the system.
and variables from a parent class.” Polymorphism: “A common interface can be used against many different underlying objects.” Encapsulation: “A language mechanism for restricting direct access to some of the object's components.”
surface of OOP. There are countless design patterns that use the flexibility of OOP to solve commonly encountered problems. Aspects like Inheritance vs Composition are important as well.
surface of OOP. There are countless design patterns that use the flexibility of OOP to solve commonly encountered problems. Aspects like Inheritance vs Composition are important as well. But let’s go back to an earlier slide I had.
the phenomenon in which the same values, or related storage locations, are frequently accessed, depending on the memory access pattern.” This means that when you load that first myX variable into memory, that is not the only thing loaded into memory, because the computer is guessing that you also need the values that are stored after the value. So it loads a lot of the memory that comes after that variable.
read or write a piece of data in the cache, which results in a main memory access with much longer latency” If all of the data you need is tightly packed together, it’s much more likely that you will not need to go into main memory to access it, which will drastically speed up your program.
read or write a piece of data in the cache, which results in a main memory access with much longer latency” If all of the data you need is tightly packed together, it’s much more likely that you will not need to go into main memory to access it, which will drastically speed up your program. But. As with anything. Measure first!
real world things or abstract ideas is something we do daily. But be mindful of how your data is stored and used, because when it comes down to it, those are the bits that matter the most.