Object-Oriented Programming/Introduction

This lesson introduces object-oriented programming.

Objectives and Skills

edit

Objectives and skills for this lesson include:

  • Understand basic object-oriented programming terminology

Readings

edit
  1. Wikipedia: Object-oriented programming
  2. Programing Logic and Design: Object-Oriented programming / Chapter 10

Multimedia

edit
  1. YouTube: Programming For Beginners - Object Orientation
  2. YouTube: Python OOP Tutorial 1: Classes and Instances
  3. YouTube: Introducing Object-Oriented Programming - Overview
  4. YouTube: Object-oriented Programming in 7 minutes
  5. YouTube: Object-oriented Programming Illustrated

Examples

edit

Activities

edit
  1. Research different programming languages and select an object-oriented programming language to use for this course. If unsure, Python3 is currently a popular choice. Based on your selected programming language, use Computer Programming/Introduction#Examples and one of the free online IDE links provided to try running a Hello World program.
  2. Research free downloadable tools for your selected programming language (interpreter/compiler, IDE, etc.). Consider downloading and installing a development environment on your system. If you set up your own development environment, test the environment using the Hello World program.
  3. Review Wikipedia: Coding conventions Research style guides or coding standards for your selected programming language. If applicable, discuss coding conventions with your classmates and agree on a standard to follow for this course.
  4. Review Wikipedia: Body mass index and MathsIsFun: Metric - US/Imperial Conversion Charts. Create a program that asks users for their weight in pounds and their height in feet and inches. Calculate and display their BMI. Format the output to one decimal place. Include a legend that displays value ranges for underweight, normal, and overweight. Be sure to indicate the source for your BMI range recommendations. Define constants for height and weight conversions and use self-documenting variable and constant names that follow the naming conventions for your selected programming language. Include comments at the top of the source code that describe the program and are consistent with the program or module documentation conventions for your selected programming language.
    Note: It is not necessary that your program be either structured or an object-oriented solution at this time. This activity is designed to ensure that you have adequate programming experience to begin the course. You will convert this program to an object-oriented solution in future lessons. If you find that you are not able to complete this program, start with the prerequisite Programming Fundamentals course.

Lesson Summary

edit
  • Object-oriented programming (OOP) is a programming model based on the concept of "objects", which may contain data, in the form of fields, often known as attributes; and code, in the form of procedures, often known as methods as accessors and mutators.[1]
  • A feature of objects is that an object's procedures can access and often modify the data fields of the object with which they are associated.[1]
  • Most object-oriented programming languages are class-based, meaning that objects are instances of classes, which typically also determine their type.[1]
  • Classes define the data format and available procedures for a given type of object.[1]
  • Classes may contain data members and member functions (known as class methods) themselves.[1]
  • Objects are instances of classes.[1]
  • Procedures in object-oriented programming are known as methods; variables are also known as fields, members, attributes, or properties.[1]
  • Class variables belong to the class as a whole; there is only one copy of each one..[1]
  • Instance variables or attributes belong to individual objects; every object has its own copy of each one.[1]
  • Member variables refer to both the class and instance variables that are defined by a particular class.[1]
  • Class methods belong to the class as a whole and have access only to class variables and inputs from the procedure call.[1]
  • Instance methods belong to individual objects, and have access to instance variables for the specific object they are called on, inputs, and class variables.[1]
  • Objects provide a layer of abstraction which can be used to separate internal from external code, to help keep your program clean and organized.[1]
  • Objects are created by calling a special type of method in the class known as a constructor.[1]
  • Encapsulation is an object-oriented programming concept that binds together the data and functions that manipulate the data, and that keeps both safe from outside interference and misuse. Data encapsulation supports data or information hiding.[1]
  • Some languages let classes enforce access restrictions explicitly, for example denoting internal data with the private keyword and designating methods intended for use by code outside the class with the public keyword.[1]

Key Terms

edit
abstraction
A technique for arranging complexity of computer systems so that functionality may be separated from specific implementation details.[1][2]
accessor
A method used to return the value of a private member variable, also known as a getter method.[3]
attribute
A specification that defines a property of an object.[4]
class
An extensible program-code-template for creating objects, providing initial values for state (member variables) and implementations of behavior (member functions or methods).[5]
encapsulation
A language mechanism for restricting direct access to some of an object's components.[6]
field
Also known as data member or member variable, is data encapsulated within a class or object.[7]
information hiding
The principle of segregation of the design decisions in a computer program from other parts of the program. See encapsulation.[8]
inheritance
An object or class being based on another object or class, using the same implementation or specifying a new implementation to maintain the same behavior.[9]
instance
A concrete occurrence of an object.[10]
method
A specification that defines a procedure or behavior of an object.[11]
mutator
A method used to control changes to a private member variable, also known as a setter method.[12]
object
A class is a template for objects, and an object is an instance of a class. When the individual objects are created, they inherit all the variables and methods from the class.[13]
overloading
The capability of using names to mean different things in different contexts.[14]
polymorphism
The provision of a single interface to entities of different types.[15]
private
An access modifier that restricts visibility of a property or method to the class in which it is defined.[16]
property
A class member, intermediate in functionality between a field (or data member) and a method, which supports reading and writing like a field using 'getter' and 'setter' method calls.[17]
public
An access modifier that opens visibility of a property or method to all other classes.[18]
state
Recorded information supporting preceding events or user interactions.[19]
static
Properties or methods of a class that apply to all instances of the class rather than to any specific instance.[20]
this, self, or Me
Keywords used in some computer programming languages to refer to the object, class, or other entity that the currently running code is part of.[21]

See Also

edit

References

edit
  1. 1.00 1.01 1.02 1.03 1.04 1.05 1.06 1.07 1.08 1.09 1.10 1.11 1.12 1.13 1.14 1.15 1.16 Wikipedia: Object-oriented programming
  2. Wikipedia: Abstraction (software engineering)
  3. Wikipedia: Mutator method
  4. Wikipedia: Attribute (computing)
  5. Wikipedia: Class (computer programming)
  6. Wikipedia: Encapsulation (computer programming)
  7. Wikipedia: Field (computer science)
  8. Wikipedia: Information hiding
  9. Wikipedia: Inheritance (object-oriented programming)
  10. Wikipedia: Instance (computer science)
  11. Wikipedia: Method (computer programming)
  12. Wikipedia: Mutator method
  13. w3schools.com C# OOP
  14. "Object-Oriented Terminology". www.d.umn.edu. Retrieved 2020-08-25.
  15. Wikipedia: Polymorphism (computer science)
  16. Wikipedia: Access modifiers
  17. Wikipedia: Property (programming)
  18. Wikipedia: Access modifiers
  19. Wikipedia: State (computer science)
  20. Wikipedia: Method (computer programming)
  21. Wikipedia: this (computer programming)