Published on

Published in: Technology
1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide


  1. 1. 1Object Oriented ProgrammingDevelopmentBy:Anoop GuptaSoftEra InformativeC-DAC TrainingEmail:softera.informative@gmail.com
  2. 2. Oops ?Object oriented programming is aprogramming paradigm which usesobjects and its interactions to designapplications and computer programs.Simula67 was the first object-orientedprogramming language. Java, Python, C++, Visual Basic .NET and Ruby are themost popular OOP languages today.2
  3. 3. Oops Features ?ClassObjectEncapsulationAbstractionPolymorphismInheritance3
  4. 4. Class ?Classes are user-defined (programmer-defined) types.Data (data members)Functions (member functions or methods)In other words, they are structures +functionsClasses are logical entity which definesbehaviors and property for Object4
  5. 5. ClassExamples -•Animals•Human•Books•Cricketer 5
  6. 6. Classes in C++A class definition begins with the keywordclass.The body of the class is contained within aset of braces, { } ; (notice the semi-colon)6Class class_Name{ ……………………..};Any valid identifierClass body (datamember + methodsmethods)
  7. 7. Object ?Object is a real time entity which existphysicallyObject occupy some space into memoryEvery object have some specific propertyand behavior but all objects from thesame class share common property andbehavior7
  8. 8. Objects ?•Animals8
  9. 9. 9What are we doing today?Introduction of:the lecturerObjectsBasic TerminologyC++the module
  10. 10. ObjectFruits10
  11. 11. Abstraction ?Abstraction is another good feature ofOOPS. Abstraction means to show onlythe necessary details to the client of theobject.Abstraction says that hide un necessarydetail from the user which are not requiredthem11
  12. 12. AbstractionAbstraction12
  13. 13. EncapsulationEncapsulation is a process of binding orwrapping the data and the codes thatoperates on the data into a single entity.This keeps the data safe from outsideinterface and misuse.Encapsulation Provide data security .13
  14. 14. EncapsulationEncapsulation defines the access levelsfor elements of that class. These accesslevels define the access rights to the data,allowing us to access the data by amethod of that particular class itself, fromaninheritance class, or even from anyother class. There are three levels ofaccess:14
  15. 15. Encapsulation– Encapsulation15
  16. 16. Polymorphism16
  17. 17. 17What is Object OrientedProgramming?An object is like ablack box.The internaldetails arehidden.Identifying objects andassigning responsibilities tothese objects.Objects communicate toother objects by sendingmessages.Messages are received bythe methods of an object
  18. 18. 18What is an object?Tangible Things as a car, printer, ...Roles as employee, boss, ...Incidents as flight, overflow, ...Interactions as contract, sale, ...Specifications as colour, shape, …
  19. 19. 19So, what are objects?an object represents an individual,identifiable item, unit, or entity, either realor abstract, with a well-defined role in theproblem domain.OrAn "object" is anything to which a conceptapplies.Etc.
  20. 20. 20Why do we care aboutobjects?Modularity - large software projectscan be split up in smaller pieces.Reuseability - Programs can beassembled from pre-written softwarecomponents.Extensibility - New softwarecomponents can be written ordeveloped from existing ones.
  21. 21. Example: The Person class#include<string>#include<iostream>class Person{char name[20];int yearOfBirth;public:void displayDetails() {cout << name << " born in "<< yearOfBirth << endl;}//...};privatedatapublicprocesses
  22. 22. 22The two parts of an objectObject = Data + Methodsor to say the same differently:An object has the responsibility to know andthe responsibility to do.= +
  23. 23. 23Basic TerminologyAbstraction is the representation of theessential features of an object. These are‘encapsulated’ into an abstract data type.Encapsulation is the practice of includingin an object everything it needs hiddenfrom other objects. The internal state isusually not accessible by other objects.
  24. 24. 24Basic Terminology:InheritanceInheritance means that one class inheritsthe characteristics of another class.This is also called a “is a” relationship:A car is a vehicleA teacher is a personA dog is an animal
  25. 25. 25Basic Terminology:PolymorphismPolymorphism means “having manyforms”. It allows different objects torespond to the same message in differentways, the response specific to the type ofthe object.E.g. the message displayDetails() of thePerson class should give differentresults when send to a Student object(e.g. the enrolment number).
  26. 26. 26Basic Terminology:AggregationAggregation describes a “has a”relationship. One object is a part ofanother object.We distinguish between compositeaggregation (the composite “owns” thepart) and shared aggregation (the part isshared by more then one composite).A car has wheels.
  27. 27. 27Basic Terminology:Behaviour and MessagesThe most important aspect of an object isits behaviour (the things it can do). Abehaviour is initiated by sending amessage to the object (usually by callinga method).
  28. 28. 28The two steps of ObjectOriented ProgrammingMaking Classes: Creating, extending orreusing abstract data types.Making Objects interact: Creating objectsfrom abstract data types and defining theirrelationships.
  29. 29. 29Historical NotesC++ owes most to C.Other ancestors are Simula67and Algol68.First versions of C++ in 1980 under thename “C with classes”. Since 1983 thename C++ is used.1990: ANSI/ISO 9899 defines a standardfor C1998: ISO/IEC 14882 specifies thestandard for C++C++ 1987
  30. 30. 30C++ and CC is a subset of C++.Advantages: Existing C libraries can beused, efficient code can be generated.But: C++ has the same caveats andproblems as C (e.g. pointer arithmetic,…).C++ can be used both as a low level andas a high level language.We focus on thehigh level aspects.
  31. 31. 31C++ and JavaJava is a full object oriented language, allcode has to go into classes.C++ - in contrast - is a hybrid language,capable both of functional and objectoriented programming.So, C++ is more powerful but alsomore difficult to handle than Java.
  32. 32. 32Module OutlineIntroductionThe non objectoriented basicsClassesDesign ApproachesTestingInheritanceAggregationPolymorphismMultifile Development
  33. 33. 33Assessment Details50% in course and 50% exam.For more details for the in courseassignment see separate handout.
  34. 34. 34BooksTeach Yourself C++ in 10 minutes,J. Liberty, SAMS 1999.C++ - How to program, Deitel & Deitel,Prentice Hall, 2001.Object Oriented Programming with C++,David Parson, Letts Educational, London1997.
  35. 35. 35WebsitesA C++ online tutorial:http://www.cplusplus.com/doc/tutorial/The C++ FAQ:http://www.parashift.com/c++-faq-liteThe homepage of Bjarne Stroustrup, theinventor of C++:http://www.research.att.com/~bsAnd many, many more!