Lecture note Data visualization - Chapter 13
Số trang: 36
Loại file: pptx
Dung lượng: 133.62 KB
Lượt xem: 2
Lượt tải: 0
Xem trước 4 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
In this lecture we learned about: Separation of interface and implementation, objects are declared as primitive type, the destructor operator, copy constructor, default constructor.
Nội dung trích xuất từ tài liệu:
Lecture note Data visualization - Chapter 13Lecture13RecapSeparationofInterfaceandImplementationObjectsareDeclaredasPrimitiveTypeTheDestructorOperatorCopyConstructorDefaultConstructorSelectiveQuestionsfrom ExerciseQ:Whatisinformationhiding?Whatisencapsulation? HowdoesC++supporttheseconcepts?Answer: Informationhidingmakesimplementationdetails, includingcomponentsofanobject,inaccessible. Encapsulationisthegroupingofdataandthe operationsthatapplytothemtoformanaggregate whilehidingtheimplementationoftheaggregate. Encapsulationandinformationhidingareachieved inC++throughtheuseoftheclass.Q:Explainthepublicandprivatesectionsoftheclass.Answer: Membersinthepublicsectionofaclassarevisible tononclassroutinesandcanbeaccessedviathe. memberoperator.Privatemembersarenotvisible outsideoftheclass.Q:Describetherolesoftheconstructoranddestructor.Answer: Theconstructoriscalledwhenanobjectiscreated, eitherbydeclaration,acalltonew,orasamemberof anobjectwhichitselfisbeingconstructed. Thedestructoriscalledwhentheobjectexitsscope, eitherbecauseitisalocalvariableinaterminating function,itissubjecttoadelete,oritisamemberofan objectwhosedestructoriscalled.Q:Whatisthedifferencebetweenacopyconstructorand acopyassignmentoperator?Answer: Thecopyconstructorcreatesandinitializesanew object.Itisusedtoimplementcallbyvalue. Thecopyassignmentoperatorcopiesintoanalready existingobject.Q:Ifaclassprovidesnoconstructorandnodestructor, whatistheresult?Answer: Thedefaultconstructorisamemberbymember applicationofadefaultconstructor.Thedefault destructorisamemberbymemberapplicationofa destructor. Chapter4InheritanceIntroductionInthischapterwewillstudy howthegeneralprinciplesofinheritanceandthe objectorientedconceptofpolymorphismrelatetocode reuse, howinheritanceisimplementedinC++, howacollectionofclassescanbederivedfroma singleabstractclass, howruntimebindingdecisions,ratherthancompile timelinkingdecisions,canbemadefortheseclasses.IntroductiontoInheritanceOnonelevelinheritanceisthefundamentalobject orientedprinciplegoverningthereuseofcodeamong relatedclassesInheritancemodelstheISArelationshipInanISArelationship,thederivedclassisabaseclass Forexample:aCircleISAShapeandaCarISAVehicle. However,anEllipseISNOTACircleInheritancerelationshipsformhierarchies Forinstance:wecanextendCartootherclasses,asa ForeigncarISACarandaDomesticcarISACarandsoContinued….AnothertypeofrelationshipisaHASArelationshipInaHASArelationship,thederivedclasshasabase class.Thistypeofrelationshipdoesnotpossesstheproperties thatwouldbenaturalinaninheritancehierarchy ForExample:AcarHASAsteeringwheelGenerally,HASArelationshipsshouldnotbemodeled byinheritance.Instead,theyshouldbemodeledwiththe techniqueofcomposition,inwhichthecomponentsare simplymadeprivatedatafieldsInheritanceinC++TheC++languageitselfmakessomeuseofinheritancein implementingitsclasslibraries.Twoexamplesare Exceptions FilesExceptionsC++definesinthe classexceptionThereareseveralkindsof exceptions,includingbad_alloc andbad_castInfigure Classesinexceptionhierarchy hasbeenshown Eachisaseparateclass,butfor allofthem,thewhatmethodcan beusedtoreturnastringthatI/OOperationInfigure streamshierarchyuses inheritanceInactual,thestreams hierarchyismorecomplex thanshownISARelationshipTheinheritancemodelsanISArelationshipAbuttonISAcomponentAbad_castISAexceptionAnifstreamISAistreamBecauseofISArelationships,thefundamentalproperty ofinheritanceguaranteesthatanymethodthatcanbe performedbyistreamcanalsobeperformedby ifstreamandthatanifstreamobjectcanalwaysbe referencedbyanistreamreferenceThereverseisnottrueContinued….whatisamethodavailableintheexceptionclassIfweneedtocatchvariousexceptionswecanuseacatch handlerandwrite: {catch(constexception&e)IcoutPolymorphisminInheritanceThecalltowhatillustratesanimportantobjectoriented principleknownaspolymorphismItistheabilityofareferencevariabletoreferenceobjects ofseveraldifferenttypesWhenoperationsareappliedtothevariable,theoperation thatisappropriatetotheactualreferencedobjectis automaticallyselectedThesameistrueforpointervariablesInthecaseofanexceptionreference,aruntimedecision ismadeClassesinInheritanceInheritanceistheprocessofderivingaclassfromabase classwithoutdisturbingtheimplementationofthebase classThebaseclassisthefoundationforinheritanceAderivedclassisacompletelynewclassthatinheritsall thepropertiesofthebaseclass,withallthepublic methodsavailabletothebaseclassbecomingpublic methodswithidenticalimplementationofthederived classThederivedclasscanthenadddatamembersand additionalmethodsandchangethemeaningoftheContinued….AderivedclassistypecompatiblewithitsbaseclassAreferencevariableofthebaseclasstypemayreference anobjectofthederivedclass,butnotviceversaSiblingclasses(i.e.,classesderivedfromacommonclass) arenottypecompatibleTheexcep ...
Nội dung trích xuất từ tài liệu:
Lecture note Data visualization - Chapter 13Lecture13RecapSeparationofInterfaceandImplementationObjectsareDeclaredasPrimitiveTypeTheDestructorOperatorCopyConstructorDefaultConstructorSelectiveQuestionsfrom ExerciseQ:Whatisinformationhiding?Whatisencapsulation? HowdoesC++supporttheseconcepts?Answer: Informationhidingmakesimplementationdetails, includingcomponentsofanobject,inaccessible. Encapsulationisthegroupingofdataandthe operationsthatapplytothemtoformanaggregate whilehidingtheimplementationoftheaggregate. Encapsulationandinformationhidingareachieved inC++throughtheuseoftheclass.Q:Explainthepublicandprivatesectionsoftheclass.Answer: Membersinthepublicsectionofaclassarevisible tononclassroutinesandcanbeaccessedviathe. memberoperator.Privatemembersarenotvisible outsideoftheclass.Q:Describetherolesoftheconstructoranddestructor.Answer: Theconstructoriscalledwhenanobjectiscreated, eitherbydeclaration,acalltonew,orasamemberof anobjectwhichitselfisbeingconstructed. Thedestructoriscalledwhentheobjectexitsscope, eitherbecauseitisalocalvariableinaterminating function,itissubjecttoadelete,oritisamemberofan objectwhosedestructoriscalled.Q:Whatisthedifferencebetweenacopyconstructorand acopyassignmentoperator?Answer: Thecopyconstructorcreatesandinitializesanew object.Itisusedtoimplementcallbyvalue. Thecopyassignmentoperatorcopiesintoanalready existingobject.Q:Ifaclassprovidesnoconstructorandnodestructor, whatistheresult?Answer: Thedefaultconstructorisamemberbymember applicationofadefaultconstructor.Thedefault destructorisamemberbymemberapplicationofa destructor. Chapter4InheritanceIntroductionInthischapterwewillstudy howthegeneralprinciplesofinheritanceandthe objectorientedconceptofpolymorphismrelatetocode reuse, howinheritanceisimplementedinC++, howacollectionofclassescanbederivedfroma singleabstractclass, howruntimebindingdecisions,ratherthancompile timelinkingdecisions,canbemadefortheseclasses.IntroductiontoInheritanceOnonelevelinheritanceisthefundamentalobject orientedprinciplegoverningthereuseofcodeamong relatedclassesInheritancemodelstheISArelationshipInanISArelationship,thederivedclassisabaseclass Forexample:aCircleISAShapeandaCarISAVehicle. However,anEllipseISNOTACircleInheritancerelationshipsformhierarchies Forinstance:wecanextendCartootherclasses,asa ForeigncarISACarandaDomesticcarISACarandsoContinued….AnothertypeofrelationshipisaHASArelationshipInaHASArelationship,thederivedclasshasabase class.Thistypeofrelationshipdoesnotpossesstheproperties thatwouldbenaturalinaninheritancehierarchy ForExample:AcarHASAsteeringwheelGenerally,HASArelationshipsshouldnotbemodeled byinheritance.Instead,theyshouldbemodeledwiththe techniqueofcomposition,inwhichthecomponentsare simplymadeprivatedatafieldsInheritanceinC++TheC++languageitselfmakessomeuseofinheritancein implementingitsclasslibraries.Twoexamplesare Exceptions FilesExceptionsC++definesinthe classexceptionThereareseveralkindsof exceptions,includingbad_alloc andbad_castInfigure Classesinexceptionhierarchy hasbeenshown Eachisaseparateclass,butfor allofthem,thewhatmethodcan beusedtoreturnastringthatI/OOperationInfigure streamshierarchyuses inheritanceInactual,thestreams hierarchyismorecomplex thanshownISARelationshipTheinheritancemodelsanISArelationshipAbuttonISAcomponentAbad_castISAexceptionAnifstreamISAistreamBecauseofISArelationships,thefundamentalproperty ofinheritanceguaranteesthatanymethodthatcanbe performedbyistreamcanalsobeperformedby ifstreamandthatanifstreamobjectcanalwaysbe referencedbyanistreamreferenceThereverseisnottrueContinued….whatisamethodavailableintheexceptionclassIfweneedtocatchvariousexceptionswecanuseacatch handlerandwrite: {catch(constexception&e)IcoutPolymorphisminInheritanceThecalltowhatillustratesanimportantobjectoriented principleknownaspolymorphismItistheabilityofareferencevariabletoreferenceobjects ofseveraldifferenttypesWhenoperationsareappliedtothevariable,theoperation thatisappropriatetotheactualreferencedobjectis automaticallyselectedThesameistrueforpointervariablesInthecaseofanexceptionreference,aruntimedecision ismadeClassesinInheritanceInheritanceistheprocessofderivingaclassfromabase classwithoutdisturbingtheimplementationofthebase classThebaseclassisthefoundationforinheritanceAderivedclassisacompletelynewclassthatinheritsall thepropertiesofthebaseclass,withallthepublic methodsavailabletothebaseclassbecomingpublic methodswithidenticalimplementationofthederived classThederivedclasscanthenadddatamembersand additionalmethodsandchangethemeaningoftheContinued….AderivedclassistypecompatiblewithitsbaseclassAreferencevariableofthebaseclasstypemayreference anobjectofthederivedclass,butnotviceversaSiblingclasses(i.e.,classesderivedfromacommonclass) arenottypecompatibleTheexcep ...
Tìm kiếm theo từ khóa liên quan:
Data visualization Lecture note Data visualization Data structures Data Visualization with C Data visualization with matlab Effective graphical displayGợi ý tài liệu liên quan:
-
Trực quan hóa dữ liệu: Vai trò & thử thách
10 trang 37 0 0 -
Ebook Eloquent JavaScript - A modern introduction to programming: Part 1
199 trang 32 0 0 -
Ebook Management support systems: Part 2 - Dr. Kamlesh Lakhwani
136 trang 31 0 0 -
Lecture Introduction to computing systems (2/e): Chapter 19 - Yale N. Patt, Sanjay J. Patel
28 trang 30 0 0 -
Ebook Introduction to algorithms (3rd edition)
1313 trang 27 0 0 -
Lecture Data Structures: Lesson 38
71 trang 26 0 0 -
Lecture Data structures and algorithms: Chapter 1 - Introduction
41 trang 26 0 0 -
Lecture note Data visualization - Chapter 22
21 trang 24 0 0 -
Lecture Data Structures: Lesson 41
18 trang 23 0 0 -
335 trang 23 0 0