Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Resource Management-Object Oriented Programming-Lecture Slides, Slides of Object Oriented Programming

Main topics in this course are object-orientation, objects and classes, overloading, inheritance, polymorphism, generic programming, exception handling, introduction to design patterns. This lecture includes: Resource, Managment, Function, Return, Destructor, Class, File, Normal, Programmer, Error, Explicit, Catch, Exception, Throw, Derived

Typology: Slides

2011/2012

Uploaded on 08/08/2012

anchita
anchita 🇮🇳

4.4

(7)

115 documents

Partial preview of the text

Download Resource Management-Object Oriented Programming-Lecture Slides and more Slides Object Oriented Programming in PDF only on Docsity!

ObjectObject--Oriented Programming (OOP)Oriented Programming (OOP)

Lecture No. 45

Lecture No. 45

Example

Example

int function1(){

int function1(){

FILE *fileptr =

FILE *fileptr =

fopen( fopen(““filename.txtfilename.txt””,,““ww””););

throw exception();

throw exception();

fclose(fileptr); fclose(fileptr);

return 0; return 0;

Second Attempt

Second Attempt

class FilePtr{

class FilePtr{

FILE * f;

FILE * f;

public: public:

FilePtr(const char *name, FilePtr(const char *name,

const char * mode) const char * mode)

{ f = fopen(name, mode);}

{ f = fopen(name, mode);}

~FilePtr()

~FilePtr() { fclose(f);

{ fclose(f); }

operator FILE * ()

operator FILE * () { return f;

{ return f; }

Resource Management

Resource Management

The destructor of the FilePtr class will close

The destructor of the FilePtr class will close

the file

the file

Programmer does not have to close the file

Programmer does not have to close the file

explicitly in case of error as well as in

explicitly in case of error as well as in

normal case normal case

Example

Example

Student::Student (String aName) : Student::Student (String aName) :

name(aName) name(aName)

/*The constructor of String can throw a

/*The constructor of String can throw a

exception*/

exception*/

Example

Example

Student::Student (String aName)

Student::Student (String aName)

try

try

: name(aName) {

: name(aName) {

catch(

catch(

Example

Example

Complex::~Complex()

Complex::~Complex()

try{ try{

throw Exception(); throw Exception();

catch(

catch( …

Syntax

Syntax

void Function1() { void Function1() {……}}

void Function2() throw () { void Function2() throw () {……}}

void Function3( )

void Function3( )

throw (Exception1,

throw (Exception1, …

… ){}

){}

► ► Function1 can throw any exceptionFunction1 can throw any exception

► ► Function2 cannot throw any ExceptionFunction2 cannot throw any Exception

► ► Function3 can throw any exception of type Exception1 orFunction3 can throw any exception of type Exception1 or

any class derived from it

any class derived from it

Object Orientation

Object Orientation

What is an object

What is an object

Object

Object

Oriented Model

Oriented Model

  Information HidingInformation Hiding

  EncapsulationEncapsulation

Abstraction

Abstraction

► ► ClassesClasses

Object Orientation

Object Orientation

Multiple inheritance

Multiple inheritance

► ►

Types of association

Types of association

  Simple associationSimple association

  CompositionComposition

Aggregation

Aggregation

► ► PolymorphismPolymorphism

Inheritance

Inheritance

C++ Constructs

C++ Constructs

Public inheritance

Public inheritance

Private inheritance

Private inheritance

► ►

Protected inheritance

Protected inheritance

Overriding

Overriding

► ►

Class hierarchy

Class hierarchy

Templates

Templates

C++ Constructs

C++ Constructs

Generic programming

Generic programming

Classes template

Classes template

►►

Function templates

Function templates

Generic algorithm

Generic algorithm

Templates specialization

Templates specialization

 Partial SpecializationPartial Specialization

 Complete specializationComplete specialization