Methodology First and Language Second -A Way to Teach Object-Oriented Programming Haibin Zhu, PhD Department of Computer Science and Mathematics Nipissing.

Slides:



Advertisements
Similar presentations
Object-Oriented Programming Basics Prof. Ankur Teredesai, Computer Science Department, RIT.
Advertisements

Object-Oriented Programming Python. OO Paradigm - Review Three Characteristics of OO Languages –Inheritance It isn’t necessary to build every class from.
Contents o Introduction o Characteristics of Constructor. o Types of constructor. - Default Constructor - Parameterized Constructor - Copy Constructor.
Department of Computer Engineering Faculty of Engineering, Prince of Songkla University 1 5 – Abstract Data Types.
OOP - Object Oriented Programming Object Oriented Programming is an approach to programming that was developed to make large programs easier to manage.
Object Oriented Programming Chapter 7 Programming Languages by Ravi Sethi.
Objectives Introduction to Inheritance and Composition (Subclasses and SuperClasses) Overriding (and extending), and inheriting methods and constructors.
1 CIS601: Object-Oriented Programming in C++ Note: CIS 601 notes were originally developed by H. Zhu for NJIT DL Program. The notes were subsequently revised.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
© 2006 Pearson Addison-Wesley. All rights reserved4-1 Chapter 4 Data Abstraction: The Walls.
7M701 1 Class Diagram advanced concepts. 7M701 2 Characteristics of Object Oriented Design (OOD) objectData and operations (functions) are combined 
Marcelo Santos – OOAD-CDT309, Spring 2008, IDE-MdH 1 Object-Oriented Analysis and Design - CDT309 Period 4, Spring 2008 Object-oriented concepts.
1 Introduction to C++ Programming Concept Basic C++ C++ Extension from C.
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
C++ fundamentals.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
OBJECT ORIENTED PROGRAMMING LECTURE 12 Instructor: Rashi Garg Coordinator: Gaurav Saxena.
Polymorphism &Virtual Functions
220 FINAL TEST REVIEW SESSION Omar Abdelwahab. INHERITANCE AND POLYMORPHISM Suppose you have a class FunClass with public methods show, tell, and smile.
BASE CLASSES AND INHERITANCE CHAPTER 4. Engineer Class.
Object Orientation An Object oriented approach views systems and programs as a collection of interacting objects. An object is a thing in a computer system.
An Object-Oriented Approach to Programming Logic and Design
OBJECT ORIENTED PROGRAMMING CONCEPTS ISC 560. Object-oriented Concepts  Objects – things names with nouns  Classes – classifications (groups) of similar.
11 Chapter 11 Object-Oriented Databases Database Systems: Design, Implementation, and Management 4th Edition Peter Rob & Carlos Coronel.
CS200 Algorithms and Data StructuresColorado State University Part 4. Advanced Java Topics Instructor: Sangmi Pallickara
Chapter 2 Introducing Interfaces Summary prepared by Kirk Scott.
Inheritance - Polymorphism ITI 1121 Nour El Kadri.
Chapter 12 Support for Object oriented Programming.
UML The Unified Modeling Language A Practical Introduction Al-Ayham Saleh Aleppo University
Nipissing University, North Bay, Ontario, Canada 1 Challenges to Reusable Services - IBM Eclipse Innovation Grant - IBM Eclipse Innovation Grant - IBM.
9-Dec Dec-15  INTRODUCTION.  FEATURES OF OOP.  ORGANIZATION OF DATA & FUNCTION IN OOP.  OOP’S DESIGN.
Chapter 12 Support for Object-Oriented Programming.
 Objects versus Class  Three main concepts of OOP ◦ Encapsulation ◦ Inheritance ◦ Polymorphism  Method ◦ Parameterized ◦ Value-Returning.
1 OOP - An Introduction ISQS 6337 John R. Durrett.
Object-Oriented Programming. Objectives Distinguish between object-oriented and procedure-oriented design. Define the terms class and object. Distinguish.
Testing OO software. State Based Testing State machine: implementation-independent specification (model) of the dynamic behaviour of the system State:
Introduction to Object-Oriented Programming Lesson 2.
OO in Context Lecture 13: Dolores Zage. Confused about OO Not alone, there is much confusion about OO many programs are claimed to be OO but are not really.
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
1 CSE Programming in C++. 2 Overview Sign roster list Syllabus and Course Policies Introduction to C++ About Lab 1 Fill Questionnaire.
Basic Concepts of OOP.  Object-Oriented Programming (OOP) is a type of programming added to php5 that makes building complex, modular and reusable web.
Presented by Ted Higgins, SQL Server DBA An Introduction to Object – Oriented Programming.
CSCI 171 Presentation 15 Introduction to Object–Oriented Programming (OOP) in C++
Structure A Data structure is a collection of variable which can be same or different types. You can refer to a structure as a single variable, and to.
Mr H Kandjimi 2016/01/03Mr Kandjimi1 Week 3 –Modularity in C++
CPS120: Introduction to Computer Science Lecture 16A Object-Oriented Concepts.
Data Structures Lecture 4: Classes in C++ Azhar Maqsood NUST Institute of Information Technology (NIIT)
Computer Programming II Lecture 5. Introduction to Object Oriented Programming (OOP) - There are two common programming methods : procedural programming.
Object-oriented programming (OOP) is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their.
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
7.1 What Is An Object Object-oriented program - Description or simulation of application Object-oriented programming is done by adopting or extending an.
Object-Oriented Programming (OOP) Lecture No. 45
Review: Two Programming Paradigms
C++ Classes & Object Oriented Programming
About the Presentations
Object-Orientated Programming
Types of Programming Languages
Object Oriented Concepts
Object Orientation Yaodong Bi, Ph.D. Department of Computer Sciences
Object Oriented Analysis and Design
Abstract Data Types and Encapsulation Concepts
Object-Oriented Programming
Inheritance Dr. Bhargavi Goswami Department of Computer Science
Object-Oriented Programming
CIS601: Object-Oriented Programming in C++
Support for Object-Oriented Programming
Object-Oriented Programming
Object-Oriented PHP (1)
The Object Paradigm Classes – Templates for creating objects
Presentation transcript:

Methodology First and Language Second -A Way to Teach Object-Oriented Programming Haibin Zhu, PhD Department of Computer Science and Mathematics Nipissing University, North Bay, Canada URL: nipissingu.ca/faculty/haibinz

Contents Introduction Six Steps to Introduce the Object-Oriented Programming Teaching inheritance in C++ Teaching Other Concepts in C++ Conclusion

Introduction Object-oriented programming is required C++ is an OOPL used to teach OOP C++ is a flexible language that needs the instructor to guide the students to master C++ and OOP. It is a failure for both teaching and learning OOP with C++ that students know how to program in C++ but not in OOP.

The Six Steps General Principles Object Class Instances Inheritance Metaclass

Step 1 Discuss fundamental principles of object- orientation with respect to conventional thinking Fundamental Principles – Everything in the world is an object [4]. – Every system is composed of objects (certainly a system is also an object). – The evolution and development of a system is caused by the interactions among the objects inside or outside the system.

Step1(cont’d) Fundamental concepts – Abstract and induction – Concretion and Deduction – Composition and Decomposition A class exercise: – Describe yourself.

Step 2 Introduce an object concept by observing the real world – Everything is an object – Object ::=, where N is an identification or name of an object; s is a state or a body represented by a set of attributes; M is a set of methods (also called services or operations) the object can perform; and X is an interface that is a subset of the specifications of all the methods of the object. – A class exercise Describe yourself by this expression

Step 3 Acquire the class concept by abstraction of many common objects – Many objects with common properties form a class – C ::=, where N is an identification or a name of the class; D is a space description for memory; M is a set of the method definitions or implementations; and X is a unified interface of all the objects of this class. – A class exercise Describe a class you belong to.

Step 4 Introduce instantiation after the class concept is learned – Every object has a class – O ::=, where N is an identification or name of the object; C is the object’s class identified by the class identification or name; and S is a body or an actual space whose values are called attributes, properties, or state. – A class exercise Describe yourself as an instance of the class you described.

Step 5 Illustrate subclasses by adding more details to an existing class and superclasses by finding common things among several classes – Specialization and generalization – C s ::=, where { C } denotes a set of superclasses identified by their identifications or names, and N, D, M, and X have the same meanings as those of C. A class exercise Describe a class that is a superclass of the class you belong to.

Step 6 (Optional) Discuss metaclasses to master completely the class and object concepts

Teaching inheritance in C++ Classification-based view of inheritance – Consistent structures, single inheritance and whole inheritance are inherent Code reuse-based view of inheritance – Inconsistent structure, multiple inheritance and part inheritance reasonable

Multiple inheritance – Multiple inheritance brings about replicated inheritances, and programmers must use a "virtual" specifier to make it clear. – Multiple inheritance and aggregation class Plane { private: Head head; Engine engines[4];//4 engines Wing wings[2];//2 wings Tail tail; public: … … }

Inheritance and overloading #include using namespace std; class A {public: A(){x = 10, y =20;}; int x,y; }; class B: public A {public: B(){i = 10, j =20;}; int i,j; }; class b_class {public: virtual void display(A a) { cout<<"b_class, a= "<<a.x<<endl; } void play(A b) { cout<<"b_class, b = "<<b.y<<endl; } }; class d_class : public b_class {public: void display(B f ) { cout<<"d_class, f = "<<f.i<<endl; } void play(B g ) { cout<<"d_class, g = "<<g.j<<endl; } }; void main() {b_class *a; d_class *b; a = new b_class(); b = new d_class(); A a1,a2; b->display(a1);//(1) b->play(a1);//(2) b->play(a2);//(3) }

Teaching Other Concepts in C++ Why constructors and destructors cannot be inherited Polymorphism and pointers – About "this" Templates Friends Operator overloading Exception handling

Constructors and destructors Constructors and destructors actually belong to the metaclass of a class. “Why can the destructors of a base class not be defined without a ‘virtual’ specifier? " – A single polymorphic function (every class has only one destructor). – "Virtual" specifiers shows that there are derived classes to be responsible for managing the spaces by themselves.

Polymorphism and pointers A single name has different meanings. Without pointers, C++ would not support polymorphism. Fruit bag assumption – “An apple can be put in a bag of fruit, but a fruit cannot be put in a bag of apple."

Templates One way to abstract – Class templates are not classes, but parameterized classes from a class template can be used as ordinary classes; – Class templates are not classes, but they can be defined by inheriting an ordinary class; and – Class templates are not the same as the Smalltalk metaclasses.

Friends Be careful to “friends” – It increase the coupling among classes – It is killing encapsulation Properties of friends – Friend has no transitivity. – Friend cannot be inherited. – Friend has no reflexivity.

Operator overloading Another way to name a member function For students, we suggest clear names const Time & Time::operator +=( unsigned n ) {//... } void main() {Time a, b, c; a+=b; //(1) a.operator +=(b); //(2) }

Exception handling A pool assumption. – Any time when the program tries (TRY) some message and – encounters a defined exception, it throws (THROW) the exception object to the pool. – After that, the program searches the pool and tries to catch (CATCH) an exception with its class identification the same as what is declared in the parameter list of the CATCH statement. – If it catches such kind of exception, it does some exception handling operations. If not, it just follows the normal procedure.

Conclusion Clear concepts and correct methodologies for students to learn OOP are very important C++ is a flexible object-oriented programming language, so that C++ programmers might use it in different ways. We must clarify which ways are good and which ways are bad. Need to mention: This teaching methodology obtains better results for mature students than un- mature students!