Introduction to OOP C++ - hybrid language improved and extended standard C (procedural language) by adding constructs and syntax for use as an object oriented language. Object-Oriented and Procedural Programming Procedural Programming sequence of statements to solve a problem. Design Technique Functional Decomposition - Top-down design Create a structure chart - Problem is broken into several tasks. Each of these is in turn further decomposed into more sub-tasks. This approach defers the details as long as possible. Upper levels are very general, lower levels are more specific. Algorithm - pseudo code is written for each module to determine the precise step by step instructions to perform that task. Advantage - intuitive and orderly Disadvantage maintenance changes tend to cascade through the program. Object Oriented Programming Design Technique Object Oriented Design - OOD Create a hierarchy of objects - Problem is broken down into objects (entities or things) that are needed in the problem. The code that causes these objects to interact is the driver program (also called the client). Object class - Description of a group of objects with similar properties and behaviors; a pattern for creating individual objects (template). They share properties, features, or attributes. 08/25/18 1
Example : Student adding a course: Functional Decomposition - Focus on actions repeat select a course if the course is open add the course increment credits until credits > 12 OOD - Focus on objects that are operated on Obj. attributes operations student name gpa banner-id add course credits drop course update credits course name add number drop credits seat count max current seat count Relationships among and between objects has a - student has a banner-id faculty has a banner-id staff has a banner-id is a student is a person faculty is a person staff is a person belongs to Slim Pickens belongs to (or is an instance of) student 08/25/18 2
Classes and Abstract Data Types class C++ construct to declare and define objects - data members variables or fields that maintain information about object - function members/methods actions or processes that operate or reveal the data member values Information Hiding The practice of hiding the implementation details with the goal of controlling access to the details and simplifying the use of the software. interface vs. implementation Example: CD player interface : buttons, volume, input slot, song number implementation: components inside C++ - keywords public and private control access to class members Encapsulation The practice of combining data and procedures to manipulate the data into a package. Abstract Data Type A data-type that employs encapsulation and information hiding to only expose in the interface the high-level operations and hide all low-level implementation details. It allows the programmer (user) to abstract from ignore the implementation details. Promotes program reliability and robustness 08/25/18 3
The Client/Server Model and Message Passing Inheritance and Polymorphism Inheritance Objects (classes) can stand alone or be part of an inheritance hierarchy. This creates relationships between classes (is a). Example: Student is a Person Student inherits all attributes of Person (name, birthdate ) C++ supports multiple inheritance a child class (derived class) can inherit attributes from more than one parent class (base class) 08/25/18 4
Polymorphism Having many forms Within an inheritance hierarchy there can be function members that have the same signature (i.e. invocation of the function is identical). Derived class function members override a parent class function member when they have an identical signature. Example: Person class has a Print() Student class has a Print() Person p; Student s; p.print(); // calls the print in person s.print(); // calls the print in student Interfaces and Components Interface The exposed high-level methods for a class (typically in a.h file) Component The hidden implementation details for a class (typically in a.o file) The programmer (class user) can refer to the interface information for how to communicate and integrate the objects. The necessary components can be placed in a container that make up the application. 08/25/18 5