C++ Training Datascope Lawrence D’Antonio Lecture 4 An Overview of C++: What is a Class/Object?

Slides:



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

15 May, 2015 CORBA Object-by-Value An overview of the value type and its IDL-to-C++ mapping. George Edwards Institute for Software-Integrated Systems Vanderbilt.
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
Chapter 3 Data Abstraction: The Walls. © 2005 Pearson Addison-Wesley. All rights reserved3-2 Abstract Data Types Modularity –Keeps the complexity of a.
OBJECT ORIENTED ANALYSIS & DESIGN Vassilka Kirova Department of Computer & Information Science NJIT.
OBJECT ORIENTED ANALYSIS & DESIGN Vassilka Kirova Department of Computer & Information Science NJIT.
Object Oriented Programming.  OOP Basic Principles  C++ Classes  September 2004  John Edgar 22.
16/22/2015 2:54 PM6/22/2015 2:54 PM6/22/2015 2:54 PMObject-Oriented Development Concept originated with simulating objects and their interactions. Adapted.
OOP Class Lawrence D’Antonio Lecture 4 An Overview of C++, Part 2.
C++ Training Datascope Lawrence D’Antonio Lecture 3 An Overview of C++
Data Abstraction and Object- Oriented Programming CS351 – Programming Paradigms.
C++ Training Datascope Lawrence D’Antonio Lecture 1 Quiz 1.
Lecture 9 Concepts of Programming Languages
Abstract Data Types and Encapsulation Concepts
1 Review: Two Programming Paradigms Structural (Procedural) Object-Oriented PROGRAM PROGRAM FUNCTION OBJECT Operations Data OBJECT Operations Data OBJECT.
State,identity and behavior of objects Sem III K.I.R.A.S.
Classes in C++ Bryce Boe 2012/08/15 CS32, Summer 2012 B.
Classes Mark Hennessy Dept. Computer Science NUI Maynooth C++ Workshop 18 th – 22 nd Spetember 2006.
Writing Classes (Chapter 4)
Sadegh Aliakbary Sharif University of Technology Fall 2011.
Object Oriented Programming Key Features of OO Approach Data encapsulation –data and methods are contained in a single unit, object –promotes internal.
Recap (önemli noktaları yinelemek) from last week Paradigm Kay’s Description Intro to Objects Messages / Interconnections Information Hiding Classes Inheritance.
An Introduction to Java Chapter 11 Object-Oriented Application Development: Part I.
SEN 909 OO Programming in C++ Final Exam Multiple choice, True/False and some minimal programming will be required.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 13 Introduction to Classes.
OOP Class Lawrence D’Antonio Lecture 3 An Overview of C++
Copyright 2004 Scott/Jones Publishing Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 7 Structured Data and Classes.
1 Inheritance. 2 Why use inheritance?  The most important aspect of inheritance is that it expresses a relationship between the new class and the base.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures C++ Review Part-I.
SMIE-121 Software Design II School of Mobile Information Engineering, Sun Yat-sen University Lecture.
© 2004 Pearson Addison-Wesley. All rights reserved September 12, 2007 Encapsulation ComS 207: Programming I (in Java) Iowa State University, FALL 2007.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Abstraction ADTs, Information Hiding and Encapsulation.
CSCI 1100/1202 April 1-3, Program Development The creation of software involves four basic activities: –establishing the requirements –creating.
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
Object-Oriented Programming Chapter Chapter
Chapter 10: Classes and Data Abstraction. Objectives In this chapter, you will: Learn about classes Learn about private, protected, and public members.
CSci 162 Lecture 10 Martin van Bommel. Procedures vs Objects Procedural Programming –Centered on the procedures or actions that take place in a program.
Introduction to Object-Oriented Programming Lesson 2.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 7: Introduction to Classes and Objects Starting Out with C++ Early.
Chapter 5 Classes and Methods II Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas, E.
Object Oriented Programming. OOP  The fundamental idea behind object-oriented programming is:  The real world consists of objects. Computer programs.
Chapter 10: Classes and Data Abstraction. Classes Object-oriented design (OOD): a problem solving methodology Objects: components of a solution Class:
Chapter 7 Classes and Methods III: Static Methods and Variables Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition)
Fusion Design Overview Object Interaction Graph Visibility Graph Class Descriptions Inheritance Graphs Fusion: Design The overall goal of Design is to.
Lecture 2 Intro. To Software Engineering and Object-Oriented Programming (2/2)
Introduction to Object Oriented Programming Lecture-3.
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.
Chapter 11 An introduction to object-oriented design.
CPSC 252 ADTs and C++ Classes Page 1 Abstract data types (ADTs) An abstract data type is a user-defined data type that has: private data hidden inside.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Copyright © 2012 Pearson Education, Inc. Chapter 4 Writing Classes : Review Java Software Solutions Foundations of Program Design Seventh Edition John.
 The Object Oriented concepts was evolved for solving complex problems. Object- oriented software development started in the 1980s. Object-oriented design.
Object-Oriented Programming Basics
OOP What is problem? Solution? OOP
Review: Two Programming Paradigms
Chapter 3: Using Methods, Classes, and Objects
About the Presentations
Object Oriented Concepts -I
Anatomy of a Class & Method
Chapter 4: Writing Classes
Lecture 9 Concepts of Programming Languages
CS212: Object Oriented Analysis and Design
Encapsulation & Visibility Modifiers
Classes and Data Abstraction
CORBA Object-by-Value
UNIT I OBJECT ORIENTED PROGRAMMING FUNDAMENTALS
Outline Anatomy of a Class Encapsulation Anatomy of a Method
Lecture 9 Concepts of Programming Languages
Presentation transcript:

C++ Training Datascope Lawrence D’Antonio Lecture 4 An Overview of C++: What is a Class/Object?

What is a class?  A class is a set of objects sharing common features.  A class defines an object’s attributes and behavior. Methods are provided to act on an object and to pass messages between objects.  A class is the basic unit of abstraction.  A class is the basic unit of modularity.  A class can be concrete or abstract.

Class Design as Type Design   Scott Meyers, Item #19   How should objects of your new type be created and destroyed?   How should object initialization differ from object assignment?   What does it mean for objects of your new type to be passed by value?

Class Design as Type Design 2   What are the restrictions on legal values for your new type?   Does your new type fit into an inheritance graph?   What kind of type conversions are allowed for your new type?   What operators and functions make sense for the new type?

Class Design as Type Design 3   What standard functions should be disallowed?   Who should have access to members of your new type?   What is the “undeclared interface” of your new type?   How general is your new type?   Is a new type really what you need?

What is an object?  An object is an instance of a class.  An object has state, behavior, identity.

What is an object? Coad-Yourdon An abstraction of something in a problem domain, reflecting the capabilities of the system to keep information about it, interact with it, or both; an encapsulation of attribute values and their exclusive services.

What is an object? OMG An object is a thing. It is created as the instance of an object type. Each object has a unique identity that is distinct from and independent of any of its characteristics. Each object offers one or more operations.

What is an object? Firesmith An object is defined as a software abstraction that models all relevant aspects of a single tangible or conceptual entity or thing from the application domain or solution space. An object is one of the primary entities in an object-oriented application, typically corresponds to a software module, and consists of a set of related attribute types, messages, exceptions, operations, and optional component objects.

What is an object? Booch From the perspective of human cognition, an object is any of the following:   A tangible and/or visible thing.   Something that may be apprehended intellectually.   Something toward which thought or action is directed.

What is an object? Booch continued. An object has state, behavior, and identity; the structure and behavior of similar objects are defined in their common class; the terms instance and object are interchangeable.

What is an object? Shlaer-Mellor An object is an abstraction of a set of real- world things such that:   All the things in the set have the same characteristic.   All instances are subject to and conform to the same set of rules and policies.

What is an object? Jacobson An object is characterized by a number of operations and a state which remembers the effect of these operations.

What is encapsulation?  Internal details of objects are concealed from the objects users (information hiding).  Both data and implementation may be hidden. The object is a black box.  Access to members is controlled through the class definition.  The accessible part of a class is called its interface.

Data encapsulation example class Clock { private: int hours; // 1-12 private int minutes; // 0-59 public: Clock(int h, int m) { if (h 12) { throw(”Hours must be between 1 and 12″); } if (m 59) { throw(”Minutes must be between 0 and 59″); } h = hours; m = minutes; } //... };

Class Invariants   The above is an example of “Programming by Contract.”   The class guarantees that   These are called class invariants

Data Members Data members can be declared as:   const – a declaration that an object is read only. The object may be stored in a CPU register.   volatile – a declaration that an object’s value may be changed asynchronously. The object may not be stored in a CPU register.

Data Members 2   static – A data member shared by all objects of a class. There is only one copy of a static member, it is not part of the object memory layout.   mutable – A data member that is allowed to be modified, even if it a member of a const object.

Is the following code legal? struct X { static int a = 2; }; main() { X my_x; X::a = 4; my_x::a = 5; }

Not legal! Cannot initialize static data member a within class. static variables are similar to extern variables.

Is the following code legal? struct X { static int a; }; main() { X my_x; X::a = 4; my_x::a = 5; }

Not legal! This is a linker error. X::a was used but never defined.

Is the following code legal? struct X { static int a; }; int X::a; main() { X my_x; X::a = 4; my_x::a = 5; }

Legal. X::a was defined before being used. Note: it is okay that X::a was not initialized.

Is the following code legal? struct X { static int a; static const int b = 3; }; int X::a = 2; main() { X my_x; X::a = 4; my_x::a = X::b; }

Legal. static const members can be declared and defined at the same time.

Is the following code legal? void func(volatile std::list li) { int n = li.front(); } Not legal! Only volatile member functions can be called on a volatile object. list::front() not a volatile function

What is a method?  A method is a member function that acts upon an object. A method is generally called for one object (exception: static members).  Commonly found methods are constructors, destructors, assignment, mutators, accessors.

Static Members #include using namespace std; class X { public: int a; void f(int b) { cout << “X::f()\n”;} }; int main() { int X::*ptiptr = &X::a; //pointer to data member void (X::* ptfptr) (int) = &X::f; //pointer to member function X xobject; xobject.*ptiptr = 10; (xobject.*ptfptr) (20); }

What is message passing?  Messages are transfers of data or requests for another object to take an action.

Message passing example   Adapter pattern