OOP in C. Cfront Original C++ compiler was just a pre- processor –generated C code which could be compiled with an existing C Compiler.

Slides:



Advertisements
Similar presentations
Understand and appreciate Object Oriented Programming (OOP) Objects are self-contained modules or subroutines that contain data as well as the functions.
Advertisements

CS 11 C track: lecture 7 Last week: structs, typedef, linked lists This week: hash tables more on the C preprocessor extern const.
C++ Language Fundamentals. 2 Contents 1. Introduction to C++ 2. Basic syntax rules 3. Declaring and using variables.
This lecture is a bit of a departure in that we’ll cover how C++’s features are actually implemented. This implementation will look suspiciously similar.
Copyright © 2014 Pearson Addison-Wesley. All rights reserved. Chapter 17 Templates.
Review What is a virtual function? What can be achieved with virtual functions? How to define a pure virtual function? What is an abstract class? Can a.
Department of Computer Engineering Faculty of Engineering, Prince of Songkla University 1 5 – Abstract Data Types.
C++ Programming Languages
Overview1 History of Programming Languages n Machine languages n Assembly languages n High-level languages – Procedure-oriented – Object-oriented/Event-driven.
Objects and Classes David Walker CS 320. Advanced Languages advanced programming features –ML data types, exceptions, modules, objects, concurrency,...
1 :)Advanced:) Visual Basic laura leventhal and julie barnes.
Introduction to Programming with Java “Object Oriented” Programming Compiling & Running Java Programs.
1) More on parameter passing: a) Parameter association b) Default parameters c) Procedures as parameters 2) Modules: Ada packages, C modules, C header.
1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 24: Dynamic Binding COMP 144 Programming Language Concepts Spring 2002 Felix Hernandez-Campos.
Abstract data types & object-oriented paradigm. Abstraction Abstraction: a view of an entity that includes only the attributes of significance in a particular.
 2006 Pearson Education, Inc. All rights reserved. Templates (again)CS-2303, C-Term Templates (again) CS-2303 System Programming Concepts (Slides.
1 Introduction to C++ Programming Concept Basic C++ C++ Extension from C.
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation - a language mechanism for restricting access to some.
Object-oriented Languages Compiler Baojian Hua
Objects and Classes David Walker CS 320. Advanced Languages advanced programming features –ML data types, exceptions, modules, objects, concurrency,...
C++ fundamentals.
Lecture 6: Polymorphism - The fourth pillar of OOP - 1.
EC-241 OBJECT-ORIENTED PROGRAMMING (OOP)
Learners Support Publications Pointers, Virtual Functions and Polymorphism.
1 Classes- Inheritance Multiple Inheritance It is possible to derive a new class from more than one base class. This is called Multiple Inheritance. Under.
Chapter 11 and 12: Abstract Data Types and Encapsulation Constructs; Support for Object Orientation Lesson 11.
MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )
CSE 332: C++ templates This Week C++ Templates –Another form of polymorphism (interface based) –Let you plug different types into reusable code Assigned.
1 Chapter 10: Data Abstraction and Object Orientation Aaron Bloomfield CS 415 Fall 2005.
1 Java Inheritance. 2 Inheritance On the surface, inheritance is a code re-use issue. –we can extend code that is already written in a manageable manner.
Module Overview n Module Title: OO Programming n Module Code: MIT3446 n Module Value: 3.0 n Duration: 15 weeks n Class-Contact Hours: Lecture15 hrs n Lab/Tutor30hrs.
Overloading Binary Operators Two ways to overload –As a member function of a class –As a friend function As member functions –General syntax Data Structures.
OOP and Dynamic Method Binding Chapter 9. Object Oriented Programming Skipping most of this chapter Focus on 9.4, Dynamic method binding – Polymorphism.
Week 14 - Monday.  What did we talk about last time?  Introduction to C++  Input and output  Functions  Overloadable  Default parameters  Pass.
OBJECT-ORIENTED PROGRAMMING (OOP) WITH C++ Instructor: Dr. Hany H. Ammar Dept. of Electrical and Computer Engineering, WVU.
Week 14 - Wednesday.  What did we talk about last time?  More C++  new  delete  Differences for structs  OOP.
C++ Programming Basic Learning Prepared By The Smartpath Information systems
Introduction to c++ programming - object oriented programming concepts - Structured Vs OOP. Classes and objects - class definition - Objects - class scope.
1 Lecture 6: Polymorphism - The fourth pillar of OOP -
Session 24 Chapter 12: Polymorphism. Polymorphism polymorphism comes from the Greek root for “many forms” polymorphism is about how we can use different.
Object-Oriented Programming Chapter Chapter
ISBN Object-Oriented Programming Chapter Chapter
Copyright © 2005 Elsevier Object-Oriented Programming Control or PROCESS abstraction is a very old idea (subroutines!), though few languages provide it.
Principles of programming languages 10: Object oriented languages Isao Sasano Department of Information Science and Engineering.
CS212: Object Oriented Analysis and Design Lecture 16: Runtime Polymorphism.
1 Future of Abstraction Alexander Stepanov. 2 Outline of the Talk Outline of the Talk  What is abstraction?  Abstraction in programming  OO vs. Templates.
1 Chapter 11 © 1998 by Addison Wesley Longman, Inc The Concept of Abstraction - The concept of abstraction is fundamental in programming - Nearly.
1 CS Programming Languages Class 22 November 14, 2000.
1 Copyright © 1998 by Addison Wesley Longman, Inc. Chapter 10 Abstraction - The concept of abstraction is fundamental in programming - Nearly all programming.
1 CSE Programming in C++. 2 Overview Sign roster list Syllabus and Course Policies Introduction to C++ About Lab 1 Fill Questionnaire.
1 Lecture 23: Dynamic Binding (Section ) CSCI 431 Programming Languages Fall 2002 A compilation of material developed by Felix Hernandez-Campos.
Classes Classes are a major feature of C++. They support – – Abstraction – Data hiding – Encapsulation – Modularity – Re-use through inheritance.
ENEE150 – 0102 ANDREW GOFFIN Abstract Data Types.
CSC241 Object-Oriented Programming (OOP) Lecture No. 17.
Copyright © 2009 Elsevier Chapter 9 :: Data Abstraction and Object Orientation Programming Language Pragmatics Michael L. Scott.
1 C++ Classes & Object Oriented Programming Overview & Terminology.
Mr H Kandjimi 2016/01/03Mr Kandjimi1 Week 3 –Modularity in C++
Chapter 12: Support for Object- Oriented Programming Lecture # 18.
C#.Net Software Development Version 1.0. Overview Inheritance Member Access Constructors Polymorphism (Name Hiding) Multilevel Hierarchy Virtual and VTable.
Object-oriented programming (OOP) is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their.
Chapter 9 :: Data Abstraction and Object Orientation
CS212: Object Oriented Analysis and Design
11.1 The Concept of Abstraction
Copyright © 2009 Elsevier Chapter 9 :: Data Abstraction and Object Orientation Programming Language Pragmatics Michael L. Scott.
Chapter 9 :: Data Abstraction and Object Orientation
More Object-Oriented Programming
Chapter 9 :: Data Abstraction and Object Orientation
Chapter 10 :: Object Orientated Programming
11.1 The Concept of Abstraction
Chapter 11 Abstraction - The concept of abstraction is fundamental in
Presentation transcript:

OOP in C

Cfront Original C++ compiler was just a pre- processor –generated C code which could be compiled with an existing C Compiler

Object-Oriented Programming Data abstraction Support for –Encapsulation –Data Hiding –Inheritance

Objects Consist of –Data - each object has its own data –Operations (methods) A class defines the data and operations for a particular type O-O languages provide support for hiding the data

structs in C Provide a mechanism for creating user- defined data types A struct allows you to group multiple data items into a single "data object" Function pointers allow you to include functions in the object's data

What doesn't a struct have? Data hiding –Everything in the header file is public this pointer –functions need object as an argument How do all objects of a class share the same methods? Inheritance

Methods Putting function pointers into each object means different objects can have different versions of the method Alternate approach is to have a virtual function table (vtable) for each "class" and put a pointer to this table in each object

One approach to inheritance #define S1_CLASS \ int x; \ int y; \ int (* get_x)(); \ int (*get_y)(); typedef struct s1 { S1_CLASS } S1; #define S2_CLASS \ S1_CLASS \ int z; \ int (*get_z)(); typedef struct s2 { S2_CLASS } S2;

vtables and inheritance vtable for a derived class contains a link to the vtable of the base class For multiple inheritance, have links to vtable of all parents

Making generic classes In C++, get generics using templates Use a #define function for the class Use a variable for the type(s) that are generic Calling the function with a particular type will generate code with the desired type in all the appropriate places

Some sources David Brumbaugh, C/C++ User's Journal, July 1, /oopc/oopc.htmlhttp://ldeniau.home.cern.ch/ldeniau/html /oopc/oopc.html pdf /ooc.pdf