1 / 22

Introduction to Object-Oriented Concepts in Computer Science

This introduction covers the basic principles of object-oriented programming, including encapsulation, inheritance, and polymorphism. It also explains the design and functionality of classes, as well as the relationships between them.

wcharron
Download Presentation

Introduction to Object-Oriented Concepts in Computer Science

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CPS120: Introduction to Computer Science Object-Oriented Concepts

  2. The Procedural Paradigm • The functions and algorithms are the focus, with data viewed as something for the functions to manipulate

  3. Object-Oriented Paradigm • Data should be placed inside the objects and that these objects should communicate with each other in the form of messages

  4. Designing a Class • Think in an object-oriented way • E.g. an answering machine encapsulates the functions of an answering machine with the data (messages). • The buttons are the equivalent of sending messages to the machine

  5. Functionality of Object-Oriented Languages • Encapsulation • Inheritance • Polymorphism

  6. Encapsulation • Encapsulation is a language feature that enforces information hiding • A class is a language construct that is a pattern for an object and provides a mechanism for encapsulating the properties and actions of the object class • We instantiate the class • Private and public are called access modifiers

  7. Inheritance • Inheritance fosters reuse by allowing an application to take an already-tested class and derive a class from it that inherits the properties the application needs • Polymorphism: the ability of a language to have duplicate method names in an inheritance hierarchy and to apply the method that is appropriate for the object to which the method is applied

  8. Polymorphism • The ability of a language to have duplicate method names in an inheritance hierarchy and to apply the method that is most appropriate for the object which the method is applied

  9. Object-Oriented Design • A problem-solving methodology that produces a solution to a problem in terms of self-contained entities called objects • An object is a thing or entity that makes sense within the context of the problem • For example, a student

  10. Object-Oriented Design • A group of similar objects is described by an object class, or class • A class contains fields that represent the properties and behaviors of the class • A field can contain data value(s) and/or methods (subprograms) • A method is a named algorithm that manipulates the data values in the object

  11. OOP • Object-oriented programming (OOP) is the process of developing programs using the object-oriented paradigm

  12. OOP Advantages: Reusability • Reusability is a major benefit of object-oriented programming

  13. OOP Advantages: Containment • Containment is a term used to describe an object that contains one or more objects as members (Passes the 'has-a' rule)

  14. OOP Advantages: Inheritance • Inheritance is the term used to describe an object that inherits properties from another object (Passes the 'is-a' rule) • The class from which an object inherits properties is called a parent class or base class • The class that inherits the properties is called a child class or derived class

  15. Classes • The definition of an object is know as a class • It is similar to using basic data structures in C++ • When you declare an object, you are said to have instantiated it (given it instances) • Objects are members of a class • Paul Millis, George Bush and George Washington being members of the human being class • The design of a class is as important as its implementation

  16. Relationships Between Classes • Containment • “part-of” • An address class may be part of the definition of a student class • Inheritance • Classes can inherit data and behavior from other classes • “is-a”

  17. Including Classes in C++ • For classes, the #include directive uses different punctuation for header (.h) files • Quotation marks are used when the header file is a source file in the same location as the program source code • Angle brackets are used when the header file is one of the compiler's pre-compiled library functions

  18. Using Header Files for Classes • Header files normally contain declarations of variables, functions and classes, but not implementations of the functions and classes

  19. Defining a Class • Functions and variables that are prototyped and declared in a class definition are called members

  20. Public vs Private • Private: Cannot be accessed outside the object • Public: Can have access to all the variables and functions public: // constructors circle(); // default constructor circle(const circle &); // copy constructor // member functions void SetRadius(float); double Area(); private: // data float radius;

  21. Constructors • Allow all data encapsulated within an object to be initialized to preset values so that errors can be avoided

  22. Member Functions • Provide a way for a programmer to pass data to and get data from an object • Implemented like a normal C++ function • Except -- The class name and the scope-resolution operator (: :) precede the function name • circle : : circle() // default constructor

More Related