Assignment On Object Oriented Design
Assignment On Object Oriented Design
Question:1DefinethetermsObject-Orientedanalysis,Object–Orienteddesignand
ObjectOrientedProgrammig .
Answer:1 ObjectOrientedAnalysis(OOA):ObjectOrientedAnalysis(OOA)isthefirst
technicalactivityperformedaspartofobjectorientedsoftwareengineering.OOAintroduces
newconceptstoinvestigateaproblem.Itisbasedinasetofbasicprinciples,whichareas follows
1.Theinformationdomainismodeled.
2.Behaviorisrepresented.
3.Functionisdescribed.
4.Data,functional,andbehavioralmodelsaredividedtouncovergreaterdetail.
5.Earlymodelsrepresenttheessenceoftheproblem,whilelateronesprovide
implementationdetails.
ObjectOrientedDesign(OOD):Ananalysismodelcreatedusingobjectoriented
analysisistransformedbyobjectorienteddesignintoadesignmodelthatworksasa
planforsoftwarecreation.OODresultsinadesignhavingseveraldifferentlevelsof
modularityi.e.,Themajorsystemcomponentsarepartitionedintosubsystems(a
systemlevel“modular”),anddatatheirmanipulationoperationsareencapsulatedinto
objects(amodularformthatisthebuildingblockofanOOsystem.).
Inaddition,OODmustspecifysomedataorganizationofattributesandaprocedural
descriptionofeachoperation.
Itishavingthefollowingfourlayers.
1.TheSubsystemLayer:
Itrepresentsthesubsystemthatenablessoftwaretoachieveuserrequirements
andimplementtechnicalframeworksthatmeetuserneeds.
2.TheClassandObjectLayer:
Itrepresentstheclasshierarchiesthatenablethesystemtodevelopusing
generalizationandspecialization.Thislayeralsorepresentseachobject.
3.TheMessageLayer:
Itrepresentsthedesigndetailsthatenableeachobjecttocommunicatewithits
partners.Itestablishesinternalandexternalinterfacesforthesystem.
4.TheResponsibilitiesLayer:
Itrepresentsthedatastructureandalgorithmicdesignforalltheattributesand
operationsforeachobject.
ObjectOrientedProgramming:Object-orientedprogramming(OOP)isacomputer
programmingmodelthatorganizessoftwaredesignarounddata,orobjects,ratherthan
functionsandlogic.Anobjectcanbedefinedasadatafieldthathasuniqueattributes
andbehavior.
OOPfocusesontheobjectsthatdeveloperswanttomanipulateratherthanthelogic
requiredtomanipulatethem.Thisapproachtoprogrammingiswell-suitedforprograms
thatarelarge,complexandactivelyupdatedormaintained.Thisincludesprogramsfor
manufacturinganddesign,aswellasmobileapplications;forexample,OOPcanbe
usedformanufacturingsystemsimulationsoftware.
Theorganizationofanobject-orientedprogramalsomakesthemethodbeneficialto
collaborativedevelopment,whereprojectsaredividedintogroups.Additionalbenefits
ofOOPincludecodereusability,scalabilityandefficiency.
Thestructure,orbuildingblocks,ofobject-orientedprogrammingincludethefollowing:
∙ Classesareuser-defineddatatypesthatactastheblueprintforindividualobjects,
attributesandmethods.
∙ Objectsareinstancesofaclasscreatedwithspecificallydefineddata.Objectscan
correspondtoreal-worldobjectsoranabstractentity.Whenclassisdefinedinitially,
thedescriptionistheonlyobjectthatisdefined.
∙ Methodsarefunctionsthataredefinedinsideaclassthatdescribethebehaviorsof
anobject.Eachmethodcontainedinclassdefinitionsstartswithareferencetoan
instanceobject.Additionally,thesubroutinescontainedinanobjectarecalled
instancemethods.Programmersusemethodsforreusabilityorkeeping
functionalityencapsulatedinsideoneobjectatatime.
∙ Attributesaredefinedintheclasstemplateandrepresentthestateofanobject.
Objectswillhavedatastoredintheattributesfield.Classattributesbelongtothe
classitself.
Question:2Differentiatebetweenprocedure-OrienteddesignandObject–Oriented
Design.
Answer:2
procedure-Orienteddesign procedure-Orienteddesign
Inproceduralprogramming,programis Inobjectorientedprogramming,
dividedintosmallpartscalledfunctions. programisdividedintosmallparts
calledobjects.
Proceduralprogrammingfollowstop Objectorientedprogramming
downapproach. followsbottomupapproach.
Thereisnoaccessspecifierin Objectorientedprogramminghave
proceduralprogramming. accessspecifierslikeprivate,public,
protectedetc
Addingnewdataandfunctionisnot Addingnewdataandfunctioniseasy.
easy.
Proceduralprogrammingdoesnothave Objectorientedprogrammingprovides
anyproperwayforhidingdatasoit datahidingsoitismoresecure.
islesssecure.
Inproceduralprogramming,overloading Overloadingispossibleinobject
isnotpossible. orientedprogramming.
Inproceduralprogramming,functionis Inobjectorientedprogramming,datais
moreimportantthandata. moreimportantthanfunction.
Question:3WhatisAbstractionandexplainitbygivingsomeexample?
Answer:3Abstraction:Abstractionmeansdisplayingonlyessentialinformation
andhidingthedetails.Dataabstractionreferstoprovidingonlyessential
informationaboutthedatatotheoutsideworld,hidingthebackgrounddetailsor
implementation.
Example:Considerareallifeexampleofamandrivingacar.Themanonlyknows
thatpressingtheacceleratorswillincreasethespeedofcarorapplyingbrakeswill
stopthecarbuthedoesnotknowabouthowonpressingacceleratorthespeedis
actuallyincreasing,hedoesnotknowabouttheinnermechanismofthecarorthe
implementationofaccelerator,brakesetcinthecar.
AdvantagesofDataAbstraction:
∙ Helpstheusertoavoidwritingthelowlevelcode
∙ Avoidscodeduplicationandincreasesreusability.
∙ Canchangeinternalimplementationofclassindependentlywithoutaffectingthe user.
∙ Helpstoincreasesecurityofanapplicationorprogramasonlyimportantdetails
areprovidedtotheuser.
Question:4Whatisencapsulationandexplainitbygivingsomeexample?
Answer:4 Encapsulation isdefinedaswrappingupofdataandinformationunder
asingleunit.InObjectOrientedProgramming,Encapsulationisdefinedasbinding
togetherthedataandthefunctionsthatmanipulatesthem.
Example:Considerareallifeexampleofencapsulation,inacompanythereare
differentsectionsliketheaccountssection,financesection,salessectionetc.The
financesectionhandlesallthefinancialtransactionsandkeeprecordsofallthe
datarelatedtofinance.Similarlythesalessectionhandlesallthesalesrelated
activitiesandkeeprecordsofallthesales.Nowtheremayariseasituationwhen
forsomereasonanofficialfromfinancesectionneedsallthedataaboutsalesina
particularmonth.Inthiscase,heisnotallowedtodirectlyaccessthedataofsales
section.Hewillfirsthavetocontactsomeotherofficerinthesalessectionand
thenrequesthimtogivetheparticulardata.Thisiswhatencapsulationis.Herethe
dataofsalessectionandtheemployeesthatcanmanipulatethemarewrapped
underasinglename“salessection”.
Question:5Whatisinheritance?Distinguishbetweensingleinheritanceandmultiple
inheritance?
Answer:5 Inheritance:Inheritance isan importantpillarofOOP(Object-Oriented
econceptof“reusability”,i.e.whenwe
wantto
createanewclassandthereisalready
aclassthatincludessomeofthecodet
hat
wewant,wecanderiveournewclassf
romtheexistingclass.Bydoingthis,w
eare
reusingthefieldsandmethodsofthee
xistingclass.
Differencebetweensingleinheritanceandmultipleinhe
ritance:
COMP SINGLE MULTIPLEINHERITA
ARISO INHERI
N TA NCE
Question:6Whatiscomplexityinsoftwaredesign?
Answer:6Softwarecomplexityisawaytodescribeaspecificsetofcharacteristicsof
yourcode.Thesecharacteristicsallfocusonhowyourcodeinteractswithotherpieces ofcode.
Themeasurementofthesecharacteristicsiswhatdeterminesthecomplexityofyour
code.It’salotlikeasoftwarequalitygradeforyourcode.Theproblemisthatthereare
severalwaystomeasurethesecharacteristics.
We’renotgoingtolookatallthesedifferentmeasurements.(Itwouldn’tbesuperuseful
todosoanyway.)Instead,we’regoingtofocusontwospecificones:cyclomatic
complexityandNPath.Thesetwomeasurementsaremorethanenoughforyouto
evaluatethecomplexityofyourcode.
Cyclomaticcomplexity:Ifwehadtopickonemetrictouseformeasuring
complexity,itwouldbeCyclomaticcomplexity.It’swithoutquestionthebetter-known
complexitymeasurementmethod.Infact,it’scommonfordevelopersoftenusethe
terms“softwarecomplexity”and“cyclomaticcomplexity”interchangeably.
Cyclomaticcomplexitymeasuresthenumberof“linearlyindependentpaths”througha
pieceofcode.Alinearlyindependentpathisafancywayofsayinga“uniquepathwhere
wecountloopsonlyonce”.
Youcalculatecyclomaticcomplexityusingacontrolflowgraph.Thisisagraphthat
representsallthepossiblepathsthroughyourcode.Ifweconvertedourcodeintoa
controlflowgraph,itwouldlooklikethis:
Ourgraphhasfournodes.Thetopandbottomonesareforthebeginningandendof
theinsert_default_value.Thetwoothernodesareforthestates
whenemptyreturnstrueandwhenitreturnsfalse.
Ourgraphalsohasfouredges.Thosearethearrowsthatconnectourfournodes.To
calculatethecyclomaticcomplexityofourcode,weusethesetwonumbersinthis
formula:M=E−N+2.
Misthecalculatedcomplexityofourcode.(Notsurewhyit’sanMandnotaC.)Eisthe
numberofedgesandNisthenumberofnodes.The2comesfromasimplificationof
theregularcyclomaticcomplexityequation.(It’sbecausewe’realwaysevaluatinga
singlefunctionormethod.)
Sowhathappensifweplugourpreviousnumbersintoourformula?Well,wegeta
cyclomaticcomplexityofM=4−4+2=2fortheinsert_default_valuefunction.This
meansthattherearetwo“linearlyindependentpaths”throughourfunction.
Thisisprettyeasytoseeinourupdatedgraphabove.Onepathwasforif
ourifconditionwastrueandtheotherwasforifitwasn’t.Werepresentedthesetwo
pathswithredarrowsoneachsideofthecontrolflowgraph.
Question:7WhatarethePrinciplesofsoftwaredesign?
Answer:7SoftwareDesignisalsoaprocesstoplanorconvertthesoftware
requirementsintoastepthatareneededtobecarriedouttodevelopasoftware
system.Thereareseveralprinciplesthatareusedtoorganizeandarrangethe
structuralcomponentsofSoftwaredesign.SoftwareDesignsinwhichtheseprinciples
areappliedaffectthecontentandtheworkingprocessofthesoftwarefromthe beginning.
Theseprinciplesarestatedbelow:
PrinciplesOfSoftwareDesign:
1.Shouldnotsufferfrom“TunnelVision”–
Whiledesigningtheprocess,itshouldnotsufferfrom“tunnelvision”whichmeans
thatisshouldnotonlyfocusoncompletingorachievingtheaimbutonother effectsalso.
2.Traceabletoanalysismodel–
Thedesignprocessshouldbetraceabletotheanalysismodelwhichmeansit
shouldsatisfyalltherequirementsthatsoftwarerequirestodevelopahigh-quality product.
3.Shouldnot“ReinventTheWheel”–
Thedesignprocessshouldnotreinventthewheelthatmeansitshouldnotwaste
timeoreffortincreatingthingsthatalreadyexist.Duetothis,theoverall
developmentwillgetincreased.
4.MinimizeIntellectualdistance–
Thedesignprocessshouldreducethegapbetweenreal-worldproblemsand
softwaresolutionsforthatproblemmeaningitshouldsimplyminimizeintellectual distance.
5.Exhibituniformityandintegration–
Thedesignshoulddisplayuniformitywhichmeansitshouldbeuniformthroughout
theprocesswithoutanychange.Integrationmeansitshouldmixorcombineall
partsofsoftwarei.e.subsystemsintoonesystem.
6.Accommodatechange–
Thesoftwareshouldbedesignedinsuchawaythatitaccommodatesthechange
implyingthatthesoftwareshouldadjusttothechangethatisrequiredtobedone
aspertheuser’sneed.
7.Degradegently–
Thesoftwareshouldbedesignedinsuchawaythatitdegradesgracefullywhich
meansitshouldworkproperlyevenifanerroroccursduringtheexecution.
8.Assessedorquality–
Thedesignshouldbeassessedorevaluatedforthequalitymeaningthatduringthe
evaluation,thequalityofthedesignneedstobecheckedandfocusedon.
9.Reviewtodiscovererrors–
Thedesignshouldbereviewedwhichmeansthattheoverallevaluationshouldbe
donetocheckifthereisanyerrorpresentorifitcanbeminimized.
10.Designisnotcodingandcodingisnotdesign–
Designmeansdescribingthelogicoftheprogramtosolveanyproblemandcoding
isatypeoflanguagethatisusedfortheimplementationofadesign.
Question:8Explaintheconceptsofdesignintermsofcohesionandcoupling?
Answer:8Cohesion andCoupling dealwiththequalityofanOOdesign.Generally,good
OOdesignshouldbelooselycoupledandhighlycohesive.Lotofthedesignprinciples,
designpatternswhichhavebeencreatedarebasedontheideaof“Loosecouplingand
highcohesion”.
Theaimofthedesignshouldbetomaketheapplication:
∙ easiertodevelop
∙ easiertomaintain
∙ easiertoaddnewfeatures
∙ lessFragile.
Coupling:
Couplingisthedegreetowhichoneclassknowsaboutanotherclass.Letusconsider
twoclassesclassAandclassB.IfclassAknowsclassBthroughitsinterfaceonlyi.eit
interactswithclassBthroughitsAPIthenclassAandclassBaresaidtobeloosely coupled.
IfontheotherhandclassA apartfrominteractingclassBbymeansofitsinterfacealso
interactsthroughthenon-interfacestuffofclassBthentheyaresaidtobetightly
coupled.SupposethedeveloperchangestheclassB‘snon-interfaceparti.enonAPI
stuffthenincaseofloosecouplingclassAdoesnotbreakdownbuttightcoupling
causestheclassA tobreak.
SoitsalwaysagoodOOdesignprincipletouseloosecouplingbetweentheclassesi.e
allinteractionsbetweentheobjectsinOOsystemshouldusetheAPIs.Anaspectof
goodclassandAPIdesignisthatclassesshouldbewellencapsulated.
Cohesion:
Cohesion isusedtoindicatethedegreetowhichaclasshasasingle,well-focused
purpose.Couplingisallabouthowclassesinteractwitheachother,ontheotherhand
cohesionfocusesonhowsingleclassisdesigned.Higherthecohesivenessoftheclass,
betteristheOOdesign.
BenefitsofHigherCohesion:
∙ Highlycohesiveclassesaremucheasiertomaintainandlessfrequentlychanged.
∙ Suchclassesaremoreusablethanothersastheyaredesignedwithawell-focused purpose.
Question:9Explainsomeoftheconceptofeffectivemodularization?Howdoes
modularizationaffectperformanceandworkallocation?
Answer:9Theroleofeffectivemodulardesigninsoftwareengineering:
Anysoftwarecomprisesofmanysystemswhichcontainsseveralsub-systemsand
thosesub-systemsfurthercontainstheirsub-systems.So,designingacomplete
systeminonegocomprisingofeachandeveryrequiredfunctionalityisahecticwork
andtheprocesscanhavemanyerrorsbecauseofitsvastsize.
Thusinordertosolvethisproblemthedevelopingteambreakdownthecomplete
softwareintovariousmodules.Amoduleisdefinedastheuniqueandaddressable
componentsofthesoftwarewhichcanbesolvedandmodifiedindependentlywithout
disturbing(oraffectinginverysmallamount)othermodulesofthesoftware.Thus
everysoftwaredesignshouldfollowmodularity.
Theprocessofbreakingdownasoftwareintomultipleindependentmoduleswhere
eachmoduleisdevelopedseparatelyiscalledModularization.
Effectivemodulardesigncanbeachievedifthepartitionedmodulesareseparately
solvable,modifiableaswellascompilable.Hereseparatecompilablemodulesmeans
thataftermakingchangesinamodulethereisnoneedofrecompilingthewhole
softwaresystem.
Inordertobuildasoftwarewitheffectivemodulardesignthereisafactor“Functional
Independence”whichcomesintoplay.ThemeaningofFunctionalIndependenceis
thatafunctionisatomicinnaturesothatitperformsonlyasingletaskofthesoftware
withoutorwithleastinteractionwithothermodules.FunctionalIndependenceis
consideredasasignofgrowthinmodularityi.e.,presenceoflargerfunctional
independenceresultsinasoftwaresystemofgooddesignanddesignfurtheraffects
thequalityofthesoftware.
Question:10Whatarethefiveelementsofcomplexsystem?
Answer:10 FiveAttributesofaComplexSystem:
HierarchicStructure:
BuildingontheworkofSimonandAndo,Courtoissuggeststhefollowing:
∙ Frequently,complexitytakestheformofahierarchy,wherebyacomplexsystemis
composedofinterrelatedsubsystemsthathaveinturntheirownsubsystems,and
soon,untilsomelowestlevelofelementarycomponentsisreached.
Simonpointsoutthat"thefactthatmanycomplexsystemshaveanearly
decomposable,hierarchicstructureisamajorfacilitatingfactorenablingusto
understand,describe,andeven'see'suchsystemsandtheirparts"
Indeed,itislikelythatwecanunderstandonlythosesystemsthathaveahierarchic
structure.
Itisimportanttorealizethatthearchitectureofacomplexsystemisafunctionofits
componentsaswellasthehierarchicrelationshipsamongthesecomponents."All
systemshavesubsystemsandallsystemsarepartsoflargersystems....Thevalue
addedbyasystemmustcomefromtherelationshipsbetweentheparts,notfromthe
partsperse"
RelativePrimitives
Regardingthenatureoftheprimitivecomponentsofacomplexsystem,ourexperience
suggeststhat:
∙ Thechoiceofwhatcomponentsinasystemareprimitiveisrelativelyarbitraryand
islargelyuptothediscretionoftheobserverofthesystem.
Whatisprimitiveforoneobservermaybeatamuchhigherlevelofabstractionfor another.
SeparationofConcerns
Simoncallshierarchicsystemsdecomposablebecausetheycanbedividedinto
identifiableparts;hecallsthemnearlydecomposablebecausetheirpartsarenot
completelyindependent.Thisleadsustoanotherattributecommontoallcomplex
systems:
∙ Intracomponentlinkagesaregenerallystrongerthanintercomponentlinkages.This
facthastheeffectofseparatingthehigh-frequencydynamicsofthe
components—involvingtheinternalstructureofthecomponents—fromthelow
frequencydynamics—involvinginteractionamongcomponents.
Thisdifferencebetweenintra-andintercomponentinteractionsprovidesa
clearseparationofconcernsamongthevariouspartsofasystem,makingitpossibleto
studyeachpartinrelativeisolation.
CommonPatterns
Aswehavediscussed,manycomplexsystemsareimplementedwithaneconomyof
expression.Simonthusnotesthat:
∙ Hierarchicsystemsareusuallycomposedofonlyafewdifferentkindsof
subsystemsinvariouscombinationsandarrangements.
Inotherwords,complexsystemshavecommonpatterns.Thesepatternsmayinvolve
thereuseofsmallcomponents,suchasthecellsfoundinbothplantsandanimals,orof
largerstructures,suchasvascularsystems,alsofoundinbothplantsandanimals.
StableIntermediateForms
Earlier,wenotedthatcomplexsystemstendtoevolveovertime.Specifically,"complex
systemswillevolvefromsimplesystemsmuchmorerapidlyiftherearestable
intermediateformsthaniftherearenot".Inmoredramaticterms:
∙ Acomplexsystemthatworksisinvariablyfoundtohaveevolvedfromasimple
systemthatworked....Acomplexsystemdesignedfromscratchneverworksand
cannotbepatcheduptomakeitwork.Youhavetostartover,beginningwitha
workingsimplesystem.
Assystemsevolve,objectsthatwereonceconsideredcomplexbecometheprimitive
objectsonwhichmorecomplexsystemsarebuilt.Furthermore,wecannevercraft
theseprimitiveobjectscorrectlythefirsttime:Wemustusethemincontextfirstand
thenimprovethemovertimeaswelearnmoreabouttherealbehaviorofthesystem.