E N D
Inheritance • InheritanceisoneofthecornerstonesofOOPbecauseitallowsforthecreationof hierarchicalclassifications • Usinginheritance,youcancreateageneralclassatthetop • Thisclassmaythenbeinheritedbyother,morespecificclasses • Eachoftheseclasseswilladdonlythoseattributesandbehaviorsthatareuniquetoit
Generalization/Specialization • InkeepingwithJavaterminology,aclassthatisinheritedisreferredtoasasuperclass • Theclassthatdoestheinheritingisreferredtoasthesubclass • Eachinstanceofasubclassincludesallthemembersofthesuperclass • Thesubclassinheritsallthepropertiesofitssuperclass
Association,Aggregation,Composition • Thesetermsareusedtosignifytherelationshipbetweenclasses • TheyarethebasicbuildingblocksofOOPS ©2017Wipro wipro.com
Association • Associationisarelationshipbetweentwoobjects • Theassociationbetweenobjectscouldbe • one-to-one • one-to-many • many-to-one • many-to-many • TypesofAssociation • Aggregation • Composition • Example:AStudentandaFacultyarehavingan association
Aggregation • Aggregationisaspecialcaseofassociation • Adirectionalassociationbetweenobjects • Whenanobject ‘has-a’anotherobject,thenyouhavegotanaggregationbetweenthem • Aggregationisalsocalleda“Has-a” relationship. • Example:CollegehasaStudentObject
Composition • Compositionisaspecialcaseofaggregation • Inamorespecificmanner,arestrictedaggregationiscalledcomposition • Whenanobjectcontainstheotherobject,ifthecontainedobjectcannotexistwithoutthe existenceofcontainerobject,thenitiscalledcomposition • Example:Aclasscontainsstudents.Astudentcannotexistwithoutaclass.Thereexists • compositionbetweenclassandstudents
HAS-Arelationship • HAS-Arelationshipisexpressedwith containership • Containershipsimplymeansusinginstancevariablesthatrefertootherobjects • Example: • TheclassHousewillhaveaninstancevariablewhichreferstoaKitchenobject • Itmeansthat,HouseHAS-AKitchen • Notethat,somethinglikeKitchenHAS-AHouseisnotvalidinthiscontext
APossibleSolutionToTheProgram classA{ intmoney; privateintpocketMoney; voidfill(intmoney,intpocketMoney) { this.money=money; this.pocketMoney=pocketMoney; } publicintgetPocketMoney(){ returnpocketMoney; } }