Danh mục

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    
10.10.2023

Phí tải xuống: 11,000 VND Tải xuống file đầy đủ (36 trang) 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 13Lecture13RecapSeparationofInterfaceandImplementationObjectsareDeclaredasPrimitiveTypeTheDestructorOperatorCopyConstructorDefaultConstructorSelectiveQuestionsfrom ExerciseQ: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. Chapter4InheritanceIntroductionInthischapterwewillstudy howthegeneralprinciplesofinheritanceandthe objectorientedconceptofpolymorphismrelatetocode reuse, howinheritanceisimplementedinC++, howacollectionofclassescanbederivedfroma singleabstractclass, howruntimebindingdecisions,ratherthancompile timelinkingdecisions,canbemadefortheseclasses.IntroductiontoInheritanceOnonelevelinheritanceisthefundamentalobject orientedprinciplegoverningthereuseofcodeamong relatedclassesInheritancemodelstheISArelationshipInanISArelationship,thederivedclassisabaseclass Forexample:aCircleISAShapeandaCarISAVehicle. However,anEllipseISNOTACircleInheritancerelationshipsformhierarchies Forinstance:wecanextendCartootherclasses,asa ForeigncarISACarandaDomesticcarISACarandsoContinued….AnothertypeofrelationshipisaHASArelationshipInaHASArelationship,thederivedclasshasabase class.Thistypeofrelationshipdoesnotpossesstheproperties thatwouldbenaturalinaninheritancehierarchy ForExample:AcarHASAsteeringwheelGenerally,HASArelationshipsshouldnotbemodeled byinheritance.Instead,theyshouldbemodeledwiththe techniqueofcomposition,inwhichthecomponentsare simplymadeprivatedatafieldsInheritanceinC++TheC++languageitselfmakessomeuseofinheritancein implementingitsclasslibraries.Twoexamplesare Exceptions FilesExceptionsC++definesinthe classexceptionThereareseveralkindsof exceptions,includingbad_alloc andbad_castInfigure Classesinexceptionhierarchy hasbeenshown Eachisaseparateclass,butfor allofthem,thewhatmethodcan beusedtoreturnastringthatI/OOperationInfigure streamshierarchyuses inheritanceInactual,thestreams hierarchyismorecomplex thanshownISARelationshipTheinheritancemodelsanISArelationshipAbuttonISAcomponentAbad_castISAexceptionAnifstreamISAistreamBecauseofISArelationships,thefundamentalproperty ofinheritanceguaranteesthatanymethodthatcanbe performedbyistreamcanalsobeperformedby ifstreamandthatanifstreamobjectcanalwaysbe referencedbyanistreamreferenceThereverseisnottrueContinued….whatisamethodavailableintheexceptionclassIfweneedtocatchvariousexceptionswecanuseacatch handlerandwrite: {catch(constexception&e)IcoutPolymorphisminInheritanceThecalltowhatillustratesanimportantobjectoriented principleknownaspolymorphismItistheabilityofareferencevariabletoreferenceobjects ofseveraldifferenttypesWhenoperationsareappliedtothevariable,theoperation thatisappropriatetotheactualreferencedobjectis automaticallyselectedThesameistrueforpointervariablesInthecaseofanexceptionreference,aruntimedecision ismadeClassesinInheritanceInheritanceistheprocessofderivingaclassfromabase classwithoutdisturbingtheimplementationofthebase classThebaseclassisthefoundationforinheritanceAderivedclassisacompletelynewclassthatinheritsall thepropertiesofthebaseclass,withallthepublic methodsavailabletothebaseclassbecomingpublic methodswithidenticalimplementationofthederived classThederivedclasscanthenadddatamembersand additionalmethodsandchangethemeaningoftheContinued….AderivedclassistypecompatiblewithitsbaseclassAreferencevariableofthebaseclasstypemayreference anobjectofthederivedclass,butnotviceversaSiblingclasses(i.e.,classesderivedfromacommonclass) arenottypecompatibleTheexcep ...

Tài liệu được xem nhiều: