Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Object Orientation Concepts

Object Orientation Concepts

This is to encourage developers to go back to the books and learn object oriented programming to write efficient code. We can't be writing code in Java, Kotlin or other object oriented programming language and our code looks like it is procedural

Avatar for Atanda Aminat Oluchi

Atanda Aminat Oluchi

November 29, 2019

Other Decks in Programming

Transcript

  1. Object Orientation I noticed that a lot of us started

    programming by jumping into writing code. We don’t bother about the fundamentals of programming or have a good programming background knowledge, then we jump into writing our first hello world program and then become lost in the world of programming asking what next. Programming is beyond just writing code. Its more of how you can abstract the complexity of a solution to a problem, write the solution in simple language then convert it to code.
  2. Object Oriented Programming • Over time, data abstraction has become

    essential as programs became complicated. Object- oriented programming is a programming paradigm based on the concept of objects, which contain data in the form of field (attribute or properties i.e. variables) and code in the form of procedures (methods). • It is basically a set of objects performing different actions as a result of calling methods that each one expose. Major principles includes: 1.Data Abstraction. 2.Encapsulation. 3.Information Hiding. 4.Polymorphism (dynamic binding). 5.Inheritance.
  3. • Because of the complexity of software, OOP has allowed

    us to be able to model problems in terms of objects and makes it relatable to objects in real life. • Understanding object oriented programming makes it easier to build applications because if we ever run into errors we can have an idea of how to debug. Why you need to understand OOP • Understanding the code written by others especially on github is also much easier when we understand OOP • Understanding OOP makes writing clean code and modeling data much easier.
  4. Classes • A class is a blueprint specifying what an

    object can do. • A class is the definition of the data format and available procedures for a given type or class of object. • A class is an extensible program-code-template OOP Concepts for creating objects, providing initial values for state (member variables) and implementations of behavior (member functions or methods). In many languages, the class name is used as the name for the class (the template itself), the name for the default constructor of the class (a subroutine that creates objects), and as the type of objects generated by instantiating the class; these distinct concepts are easily conflated
  5. Objects • Objects can be seen as entities on its

    own. It has a state and can perform some actions. It is more like a noun. It can be relatable to a real world object such as apple which can be an instance of a class fruit or it can represent abstract entities such as open a file. OOP Concepts • An object is a block of memory allocated and configured according to a design/definition. • Every object is an instance of a class • Object are created by calling the constructor method in the class. Therefore, classes are necessary for objects to be created.
  6. Interfaces • An interface is a description of the actions

    that an object can do... for example when you flip a light switch, the light goes on, you don't care how, just that it does. • In Object Oriented Programming, an Interface is a description of all functions that an object must have in order to be an "X". Again, as an example, OOP Concepts anything that "ACTS LIKE" a light, should have a turn_on() method and a turn_off() method. • The purpose of interfaces is to allow the computer to enforce these properties and to know that an object of TYPE T (whatever the interface is ) must have functions called X,Y,Z, etc
  7. Encapsulation • Encapsulation led to the OOP concept of data

    hiding as it binds together the data and functions that manipulate the data in a class by keeping them safe from outside interference and misuse. • It hides how a class does its business but allows other class make requests of it. Features of OOP Inheritance • This is when a new class is created from existing one. Inheritance allows easy reuse/extension and/or modify the behavior of preexisting classes. • Sub classes can override the methods defined by super-classes. Inheritance represents ‘is-a-type’ relationship
  8. Polymorphism • This is when different classes is used interchangeably

    even though one implements its methods differently. • Polymorphism is achieved by using method overloading(define methods with the same name), operator overloading and method overriding(subclass overrides an implementation in its superclass) Features of OOP Data Abstraction • This is the programming process of creating a data type, usually a class, that hides the details of the data representation in order to make the data type easier to work with. • Data abstraction involves creating a representation for data that separates the interface from the implementation so a programmer or user only has to understand the interface, the commands to use, and not how the internal structure of the data is represented and/or implemented.
  9. DATA ABSTRACTION The user does not need to understand the

    details of how a phone call is placed or how the Internet works. These details are abstracted away from the phone's interface in order to make the phone easier and more effective to use. The design of the mobile or smartphone clearly separates the interface from the implementation. The user can learn the functions of the phone without ever having to know anything about how the phone works internally. Smartphone Example An example in the real-world is a mobile or smartphone. The typical smartphone user does not know how calls are made, or how the phone accesses the Internet, or even how data is stored in the phone. Instead, the mobile or smartphone user is provided with an interface that hides these details from them. Making a call simply involves selecting a contact's phone number. Accessing the Internet involves selecting an icon on the screen.
  10. Features of OOP • In addition, information hiding effectively decouples

    the calling code from the internal workings of the object or function being called, which makes it possible to change the hidden portions without having to also change the calling code. • Encapsulation is a common technique programmers use to implement information hiding. Information hiding • This is the process of hiding the details of an object or function. • The hiding of these details results in an abstraction, which reduces the external complexity and makes the object or function easier to use.
  11. Inheritance vs Composition • Composition means that one class contains

    an instance of another and uses its capabilities. i.e. One or more members of a class are objects of another class type. “has-a” relation between classes. For example, “every person has a date of birth” Features of OOP • Inheritance is a mechanism in which one class acquires the property of another class. For example, a child inherits the traits of his/her parents. With inheritance, we can reuse the fields and methods of the existing class. Hence, inheritance facilitates Reusability and is an important concept of OOPs.