您的当前位置:首页正文

Sonar

2021-11-28 来源:步旅网
SonarJWhitePaper

SonarstandsforSoftwareandArchitecture.Itismeanttosupportsoftwaredevelopersandarchitectsintheirdailywork.

Softwareoveritslifecycleneedstobechanged,adapted,enhancedorextended.Therearedifferentmainchallengesdealingwithsoftwareprojects:1.Managingtheoverallsoftwaredevelopingprocess2.Gettingdowntotherealrequirements3.Buildingahealthysoftwarebasis

Point1and2areexploredinbroaddepth.Point3isoftenunderestimatedinitsimportance,butfinallythesourcecode(orwhatisdeployed)doesthejobandneedstobeenhancedandchangedmanytimesoveritslifecyclebydifferentdevelopers.Toamortizethemoneyinvestedintothedevelopmentofasoftwaresystemitslifetimeshouldhaveanadequate

length-thelongeritrunsthebetter.Forsoftwaretoberunoveralongperiodoftimeitmustbepossibletotestiteffectivelyandmakechangestoitwithoutenormousextracostsandrisks.Moreovernewdevelopersshouldbeabletounderstandthesystemwithinareasonabletimespan.

Ifwewanttoachievethisgoalweneedtokeepinmindtheinternalstructureofthesoftware(itsarchitecture)andsomeotherbasischaracteristicsrelatedtotechnicalquality.Ahealthysoftwarebasisisneededtomanageadevelopmentprojectsuccessfullyoveralongerperiodintime.Documentationisrequired,butitdosnotpreventasoftwaresystemtoperformpoorly–the software itself does not care about documented features (“The software is the design” [ASD]).Gettingtherealrequirementsworkedout,whichinitselfisalreadydifficultandreally important, won’t help if technical quality is not. „Quality is terrible as a control variable.Youcanmakeveryshort-termgains(daysorweeks)bydeliberatelysacrificingquality,butthecost–human,business,andtechnical– is enormous“[EXP].The software is designed upfront with some basic ideas (a so called ‘architecture vision’) emergedfromateamofarchitects.Everyoneintheteammoreorlesscommitstothisvision.Furthermore nobody in the development team would say “let us discard effective testability”, “lets go and make the code overwhelmingly complex”, “lets go and use 10 different xml parsers and logging frameworks” -no!Everyonewouldsay “let’s go and make our job easier byassuringacertainleveloftechnicalqualitytocopewiththerealexistingcomplexity–theimplementation of what the end user needs”. So everyone would naturally commit to the following statement: „Forsoftwaretobetestedeffectively,itmustbedesignedfromthestartwith that goal in mind … Testability, like quality itself, cannot be an afterthought: it must be consideredfromthestart–beforethefirstlineofcodeiseverwritten “ [LSD].

Page1

Sotherearetwomaingoalstoachieve:

Howtoavoidthattherealstructureofthesoftwaredecouplesitselffromitsplannedarchitecture.

Howtoassureacertainleveloftechnicalqualitybyenhancingunderstandabilityandtestability,whilecontrollingcomplexity.Thiscanbedoneby:

Managingtheoveralldependencystructureactively.Controllingcomplexityactively.

Integratingbothactivitiesdirectlyintothedevelopmentcycle

Sonarbasicallyclosesthegapbetweenthespecificationofalogicalarchitecturedescriptionintermsoflayers,subsystemsandverticalslicesandthemostimportantartifact:thesourcecode.Ithelpstospotpotentialproblemsoftechnicalqualityrelatedaspects.Sonardoesthiswithoutdividingtheteamintheoneswhochecktheachievementofthetwomaingoalsandtheonesdevelopingthesoftware.SonarisalightweightJava-basedtoolthatcontrolscertainprojectguidelinesduringthedevelopingphase.Theanalysisrunsautomaticallyeverytimethedevelopersavessourcecodechanges.

Awordonactivelymanagingdependencies

Thesoftwareshouldadheretothealloweddependenciescomingfromalogicalarchitecturedescription for a good reason and the software should avoid “unhealthy” dependency constructstoacertainlevel(atleasttopackagelevel).

„Guideline: No Cycles between Packages. If a group of packages have cyclic dependency thentheymayneedtobetreatedasonelargerpackageintermsofareleaseunit.Thisisundesirablebecausereleasinglargerpackages(orpackageaggregates)increasesthelikelihood of affecting something.“[AUP]“Thedependenciesbetweenpackagesmustnotformcycles.” [ASD]

„Cyclic physical dependencies among components inhibit understanding, testing and reuse … Everydirecteda-cyclicgraphcanbeassigneduniquelevelnumbers;agraphwithcyclescannot … A physical dependency graph that can be assigned unique level numbers is said to be levelizable … In most real-worldsituations,largedesignsmustbelevelizableiftheyaretobe tested effectively … Independent testing reduces part of the risk associated with software integration “ [LSD]

Page2

Divisionofaproject:TheSoftwareArchitectureModel

Sonarinternallyusesamodelforthedivisionofaprojectasmainlydescribedin[AUP](andmanyothersources).Itisawidelyadoptedmethodofdescribingtheoverallsoftwarearchitecture(staticview).

Project1*Layer1*Subsystem1*Package1*Compilation-Unit1*Type1*Named-Interface1*Vertical-SlicePage3

Howtofindtheoverallstaticstructureforaproject?

Step1:Dividehorizontally

Firstofallyoushoulddevelopanideaofthetechnicallayersdividingyourprojecthorizontallyandtheirinterdependencies.Typicallayersare:ViewControllerDomainData-Access…

Thiscouldleadtothefollowingoverallpicture:

ProjectViewControllerDomainData-AccessNotethatthisisaverysimplifiedexamplethatmaynotbeappropriateforareallifeproject–maybeitwouldbeagoodideaofinvertingtheusesdependencyofthedomainlayertothedata-accesslayers(seediscussionin[ASD]).

Page4

Step2:Dividevertically

Theverticaldivisionisnormallydrivenbybusinessorapplicationlogicrelatedaspectsfinding divisions like supplier, customer, user, … with suggested uses dependencies.Thiscouldleadtothefollowingpicture:

ProjectSupplierCustomerUserViewControllerDomainData-Access=emergedsubsystem

Dividingtheprojectverticallyhasledtoalotofbusiness-logic-orientedsubsystems.

Page5

Step3:Addpuretechnicalsubsystems

Normallyitisnecessarytocreatesubsystemsdealingwithpuretechnicalaspects.Inthisexampleaneventnotificationsubsystemwillbeintroducedtoconnecttheviewwiththe

domainlayeravoidingadirectcycliccoupling.Itwouldbepossibletointroduceanotherlayerforourfirsttechnicalsubsystem(maybecalledfoundation)butitisalsopossibletoplacethesubsysteminthedomainlayerdirectlywithoutbreakingtheallowedlayerdependencies.ProjectSupplierCustomerUserCommonViewControllerdomain::evfDomainData-AccessThesubsystemiscalledevf(EventFramework)anditwasaddedtoanewvertical-slice

common,indicatingthatitisatechnicalorientedvertical-slice.Itsfullyqualifiednamewouldbedomain::evf,likeallotherswouldhavesuchafullyqualifiedname(layer-name::vertical-slice-name).

Step4:Definethemappingfromphysicalpackagestologicalsubsystems

Itisagoodideatohaveafixedmappingandnamingschemeforpackagesassignedtosubsystems(whichpackagesimplementasubsystem).Forexample:

[company-prefix].[vertical-slice-name].[layer-name]

Everypackagestartingwithanidenticalprefixbelongstothesamesubsystem.Forexamplethefollowingpackagesimplementdomain::evf

com.hello2morrow.application.common.domain.event

com.hello2morrow.application.common.domain.event.generationcom.hello2morrow.application.common.domain.event.dispatcher

Page6

Thebasicconfigurationidea

Sonar’s basicconfigurationideaistoseparateglobalprojectsettingsfromindividualviewsofdeveloperteams.

Theprojectdescriptioncontains:

LogicalarchitecturedescriptionMappingofpackagestosubsystemsAssertionsupportsettings

Thresholdsforcomplexitychecks

Theworkspacedescriptioncontainstherelevantpartateamorasingledeveloperworkson.

Summary

Controllingandmanagingalloweddependenciesbetweenlogicalcomponentsofasoftwaresystemisnotjustanoptionformediumandlargeprojects–itisapreconditionforsuccess.Thisassumptionisheavilyunderpinnedbyrelevantliterature(seereferences),researchandpracticalexperience.

Thereforeyoumusthaveastrategyfordependencymanagement,ifyouwanttomakeamediumorlargeprojectsuccessfulwithoutriskingsignificantscheduleorbudgetoverruns.Toimplementsuchastrategy,youneedatleastoneperson,whichtakesresponsibilityfortheoverallstructureofthesystem.Inmanycasesthisresponsibilitywillbetakenbytheleadingsoftwarearchitect.Buthowcanthispersonenforceagivenarchitecturalsoftwarestructure?Onewaywouldbetousesomeopensourcetools(e.g.JDepend)toanalyzedependenciesandcomputesomeoverallmetrics.Thisapproachwillworktoacertaindegree,butrequiresalotofmanualeffort.Therearetwoproblemswiththatapproach:

Noneoftheopensourcetoolsknownbyussupportsthedefinitionofanoveralllogicalarchitecture,i.e.thedefinitionoflegalandillegaldependenciesbetweenlogicalcomponents.

Thereforeitrequiresasignificantmanualefforttofindarchitectureviolations.Moreovereachviolationmustbecommunicatedtotheteammemberthatcreatedit.Ifyoucheckthemarketforcommercialtoolsyouwillfindsolutionsthatallowthedefinitionofalogicalarchitecturetoacertaindegree.Youwillfindsupportforsubsystemsandlayers(nestedsubsystemsinsideofa\"supersubsystem\").Neverthelesssomeissuesremain:Sinceverticalslicesarenotsupported,theefforttocreatealogicalarchitecturecanbesignificantlyhigher.

Stilladetectedarchitectureviolationmustbecommunicatedtothepersonthatcreatedit.Thereforethesoftwarearchitectcaneasilyfindhimselfbecomingacommunicationbottleneck.

Page7

Currently(June2005)wedonotknowanysolution,thatsupportsalightweightintegrationintothedeveloper'sIDE.SonarJoffersananswertoalloftheseissues.Itsupportstheincrementaldefinitionofa

logicalarchitecture.ThearchitectureisstoredinanXMLfilethatcanbeeasilydistributedtothewholedevelopmentteam.VersioningandchangemanagementissupportedbyusingstandardsolutionslikeCVSorSubversion.Developersstaywithintheirwellknown

developmentenvironmentandarenotifiedimmediatelyifachangecausesanarchitectureviolation.Inmostcasesnoextracommunicationisneededtofixtheproblem.

SonarJallowsyoutoenforceadefinedlogicalarchitectureevenforverybigJavaprojects.Thismajorbenefitcomeswithoutimposinganymajoradditionalefforttothearchitectortothedevelopmentteam.Efficiencywillbeincreasedwhilecommunicationoverheadisminimized.

References

[TOS]TestingObject-OrientedSystems,Beizer,Addison-Wesley2000[ASD]AgileSoftwareDevelopment,RobertC.Martin,PrenticeHall2003[LSD]Large-ScaleC++SoftwareDesign,JohnLakos,Addison-Wesley1996[AUP]ApplyingUMLAndPatterns,CraigLarman,PrenticeHall2002[EXP]ExtremeProgramming,KentBeck,Addison-Wesley1999

MoreInfos:

hello2morrowGmbHMaxstr.9D-82335Berg+49-8151-970705

Email:info@hello2morrow.dewww.hello2morrow.dePage8

因篇幅问题不能全部显示,请点此查看更多更全内容