1 / 14

Object Oriented Programming

Object Oriented Programming. A brief review of what you should know about OOP. Programming Paradigms. What is a paradigm? A model, pattern, or typical example A world-view used in doing something What are programming paradigms? Virtual computer models for writing code

enan
Download Presentation

Object Oriented Programming

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. Object Oriented Programming A brief review of what you should know about OOP

  2. Programming Paradigms • What is a paradigm? • A model, pattern, or typical example • A world-view used in doing something • What are programming paradigms? • Virtual computer models for writing code • Examples of programming paradigms • Machine code, assembly language • Structured programming; OOP

  3. Structured programming • Early paradigms focused on the hardware • This approach focused on execution sequence, program flow • Many programmers wrote “spaghetti” code • In 1968, Edgar Dijkstra published a letter: • GOTO considered harmful • Structured logic more readable: • If-then-else, while-loops, single-entry/exit blocks

  4. The OO Paradigm • In 1976, Niklaus Wirth (neeklouse veert) Algorithms+Data Structures = Programs • Don’t focus on just algorithms (code flow) • Balance data & algorithm emphasis at every level of programming • Use modules that include data structure and operations

  5. OOP objects • OOP is based on objects that have data and operations (methods) • The data describes the object’s • State, and • Properties • The methods describe • What you can do to the object, and • What you can have it do for you

  6. Prototype and Instance Objects • Most OO models allow dealing with objects in two ways: • Prototype objects are models for lots of similar objects: car, person, pet, package • Instance objects are specific examples: my 1996 red Civic, Jay Leno, Sarah’s puppy, my Christmas gift from my son Eric • In some languages, prototype objects are called classes and/or types

  7. Object interaction • Objects interact with each other using • Messages! • In some languages, messages are implemented by function calls • When you click on an object to get a context menu and then select a choice from the menu, you are “sending it a message” to perform that method (operation) • It may cause a return message (return value)

  8. Features of OOP • Programming languages that support OOP provide 3 features: • Encapsulation • Polymorphism • Inheritance

  9. Encapsulation • Encapsulation is the OOP feature that provides container modularity 2 ways - • Grouping: allowing related data and a set of operations to be grouped (remember Wirth?) • Hiding: protecting the internal workings of the “black box” and defining the external interface or how you can interact with the box

  10. Polymorphism • Polymorphism is language support for using the same name for similar operations on different kinds of objects • It would be very disappointing to need to learn separate names or operators for adding ints, floats, and doubles instead of just using “+” for each of them

  11. Polymorphism in C++ • Polymorphism is provided in C++ by • Automatic type conversions • Function & operator overloading • Inheritance • Member function overriding • Virtual functions and pure virtual functions • Templates • + overload resolution is involved in all of these • We will use each of them in this class!

  12. Inheritance • In OOP, inheritance is a form of “factoring” • An expression can be easier to calculate if you separate out a common factor • If a program uses the same code several places, “factor” it out as a function to call • If a bunch of objects have shared subsets of data and operations, “factor” out a base class (and only maintain it one place)

  13. Inheritance and Sub-classes • The usual reason why objects share data properties and operations is sub-classing • Cars, trucks, busses, boats, and airplanes share many properties and operations because they are all vehicle sub-classes • Students, faculty, and staff share object properties and operations because they are all people

  14. C++ Features to Review • Here are some OOP features of C++ • Public, private, and protected in classes • Defining classes using inheritance • Visibility rules in derived classes (inheritance) • Function overloading • Operator overloading (including I/O: << and >>) • Differences for member functions • You should review all of these!

More Related