Fundamental Concepts of Object Oriented Programming

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

Replace polymorphism with composition where possible.

👍︎︎ 5 👤︎︎ u/aidenr 📅︎︎ Nov 16 2020 🗫︎ replies

i like this explanation from /r/rust : https://www.reddit.com/r/rust/comments/jrgwkn/can_rust_be_considered_object_oriented/gbt6rzk/

The claim is that inheritance was a hack to implement polymorphism, and what you want is Interfaces / Concepts / Traits / TypeClasses

👍︎︎ 2 👤︎︎ u/Snakehand 📅︎︎ Nov 16 2020 🗫︎ replies

It doesn't undermine the whole point of inheritance and it's not a hack. The problem is people often insist on presenting examples that are full of inconsistencies. Internally, within our software, there are plenty of clean hierarchies that are perfectly well modelled with inheritance, which works very well and is very flexible in those cases. It's because they are specifically created as hierarchies, and are not just some squishy set of relationships that may exist in various real world scenarios that so often get used to demonstrate the failures of OOP and/or inheritance.

👍︎︎ 2 👤︎︎ u/Full-Spectral 📅︎︎ Nov 16 2020 🗫︎ replies
Captions
the four fundamental concepts of object-oriented programming are abstraction encapsulation inheritance and polymorphism before considering what they mean first consider what is an object an object is a thing from the real world it could be a car a boat or a book but it might not be something physical that you can touch it could be a dental appointment a seat reservation for the cinema or a bank account in the realm of object object-oriented programming an object is anything of interest to the software application that you're building it's anything that you want to store and process data about another name for an object is an entity this leads us to the first fundamental concept of object-oriented programming namely abstraction abstraction means to simplify reality for example a person is an object but if you were designing a new application to process data about a person it's unlikely that you'd be interested in everything there is to know about a person rather you would only concern yourself with the data that are relevant and the tasks that you want to perform with those data to create objects programmatically you need a class a class is a template for creating objects a class is code written by a programmer to define the attributes and the operations of an object attributes describe the object they're sometimes referred to as fields because they contain data most programmers know them as properties properties are coded within the class either as public variables or as property procedures operations are actions that can be done to or performed by the object they're sometimes referred to as behaviors but more commonly they're known as methods methods are programs within the class that are coded either as procedures or functions a class is a template for creating objects and it's often compared with a pastry cutter because once it's been written it can be used to create many objects of the same type in fact a class is sometimes referred to as a type each object is an instance of a class in the computer's memory creating an object from a class is therefore known as instantiation once these objects have been created their properties can be assigned values making each object of the same type a unique entity each property is defined in the class by a property procedure which may include code to validate a property value while it's being assigned this helps to ensure the integrity of the data contained within the object the property values that have been assigned to an object are collectively known as the state of the object it's also possible to assign values to properties while an object is being instantiated by means of a special method called new this method is known as the constructor the second fundamental concept of object-oriented programming is encapsulation this means to hide the complexity of the inner workings of an object from the programs and the programmers that make use of it it's often referred to as information hiding because the data contained within an object and the functions that manipulate the data are bound together and therefore safe from outside interference in some big software development projects it's common for more experienced programmers to write the classes that will be used by the junior programmers a class might be made available in the form of a class library indeed some software development companies specialise in developing new classes to be used by other software developers compiled class libraries protect their intellectual property to write code that will create an object from a class then set its properties and call its methods it's not necessary to understand the inner workings of the class all the programmer needs to know is the name of the class the properties and methods available and any data that need to be supplied when they're called in other words all our programmer really needs to know about is the interface of the class the implementation code of those properties and methods can remain a mystery this greatly simplifies the use of objects and helps to ensure that the data and operations encapsulated within are safe the third fundamental concept of object-oriented programming is inheritance this means that a class can derive its methods and properties from another class inheritance can result in a hierarchy of classes for example this person class defines the methods and properties of a person object an employee in a business is also a person so through inheritance an employee class derives the methods and properties of the person class an employee is a type of person a customer of the business is also a person so through inheritance a customer class also derives the methods and properties of the person class a customer is a type of person an employee class can have some extra properties and methods of its own it can extend the person class and so can a customer but it need not stop there a programmer is a type of employee and so is a manager and a cleaner inheritance defines type of relationships the class at the start of the inheritance hierarchy is called the base class any class that derives from another class is called a sub class any class that is derived from is called a superclass the final fundamental concept of object-oriented programming is polymorphism polymorphism means that a class can implement an inherited method in its own way the person class at the base of this hierarchy has a method which will save details of any object created from the person class perhaps to a database thanks to inheritance all of the classes in this hierarchy do exactly the same thing but it may be necessary for a customer's details to be saved differently perhaps to a different database polymorphism allows for this the customer class can override the workings of any method or property that it inherits with a new version of its own different forms of the same type of object with the same interface can behave in different ways polymorphism literally means many forms to recap the fundamental concepts of object-oriented programming abstraction means to simplify reality and focus only on the data and processes that are relevant to the application being built encapsulation means that data and the programs that manipulate those data are bound together and their complexity is hidden inheritance means that a class can derive its methods and properties from another class this might result in an extensive hierarchy of superclasses and subclasses polymorphism means that different subclasses of the same superclass which therefore share the same interface can implement those interfaces in their own ways by overriding the code of the methods they inherit
Info
Channel: Computer Science
Views: 36,790
Rating: 4.9621015 out of 5
Keywords: Object Oriented Programming, OOP, abstraction, encapsulation, inheritance, polymorphism, object, entity, class, type, attribute, field, property, property procedure, operation, behaviour, method, function, procedure, instantiate, constructor, class library, DLL, dynamic link library, override, base class, subclass, superclass, programming, code, computer science, computing, A level
Id: m_MQYyJpIjg
Channel Id: undefined
Length: 9min 15sec (555 seconds)
Published: Sun Nov 01 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.