《软件体系结构》课件 14-应用案例_第1页
《软件体系结构》课件 14-应用案例_第2页
《软件体系结构》课件 14-应用案例_第3页
《软件体系结构》课件 14-应用案例_第4页
《软件体系结构》课件 14-应用案例_第5页
已阅读5页,还剩39页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

应用案例软件体系结构课程组本节内容KWIC案例分析1图书借阅系统案例分析22In1974,Parnasproposedthefollowingproblem,TheKWIC(keyword-in-context)indexsystem(KWIC索引系统)软件体系结构研究的经典案例acceptsanorderedsetoflines(接受一些行)eachlineisanorderedsetofwords(每行有若干词)eachwordisanorderedsetofcharacters(每个词由若干字符组成)anylinemaybe“circularlyshifted”byrepeatedlyremovingthefirstwordandappendingitattheendoftheline(每行都可以循环移位:重复地把第一个词删除,然后接到行末)TheKWICindexsystemoutputsalistingofallcircularshiftsofalllinesinalphabeticalorder.(KWIC把所有行的各种移位情况按照字母表顺序输出)KWIC-Functional

RequirementsMaryShaw,DavidGarlan.SoftwareArchitecture:PerspectivesonanEmergingDiscipline.The3rdChapter.

AthirdwayforstylestobecombinedistoelaborateonelevelofAthirdwayforstylestothirdwayforstylestoAwayforstylestoAthirdforstylestoAthirdwaystylestoAthirdwayfortoAthirdwayforstylesbecombinedistocombinedistobeistobecombinedtobecombinediselaborateonelevelofonelevelofelaboratelevelofelaborateoneofelaborateonelevelAthirdwayforstylestobecombinedistocombinedistobeelaborateonelevelofforstylestoAthirdwayistobecombined

levelofelaborateone

ofelaborateonelevel

onelevelofelaborate

stylestoAthirdwayfor

thirdwayforstylestoAtoAthirdwayforstylestobecombinedis

wayforstylestoAthirdInput(输入)Circularshifts(循环移位)Order&Output(排序输出)KWIC-Functional

RequirementsACaseforKWICModifiability(可修改性)ChangeinAlgorithm(算法的变化):batchvs.incrementalChangeinDataRepresentation(数据表示方式的变化)linestorage,explicitvs.implicitshiftsEnhancementtosystemfunction(系统功能的可扩展性)e.g.,eliminatelinesstartingwithtrivialwordse.g.,inputlinesfromadatabaseorfromUIe.g.,delete,modifyoraddtolinesfromtheoriginalshiftedlinesPerformance(性能):Bothspaceandtime(时空复杂性)Reusability(系统构件的可复用性)Towhatextentcanthecomponentsserveasreusableentities.KWIC-Non-functional

Requirements采用“主程序-子过程”风格、对系统进行功能分解,是最自然的想法,也是“面向过程的编程”的主要思路。Decomposestheproblemaccordingtothefourbasicfunctionsperformed:input,shift,alphabetize,andoutput.(分为四个基本功能:输入、移位、排序、输出)Thesecomputationalcomponentsarecoordinatedassubroutinesbyamainprogramthatsequencesthroughtheminturn.(主程序按次序调用这四个模块)Dataiscommunicatedbetweenthecomponentsthroughsharedstoragewithanunconstrainedread-writeprotocol.(通过共享的数据存储和无约束的读-写协议在模块之间进行数据交换)KWIC-MainProgram/SubroutinewithSharedDataKWIC-MainProgram/SubroutinewithSharedDatachar[]chars_Charactersfromtheinputfilearestoredinacharacterarraynamedchars_.Wordsaredelimitedbyasinglespacecharacter.int[]line_index_Anintegerarray,whichkeepsindicesofcharactersfromthecharacterarray.Eachindexkeptinthelineindexarrayistheindexofthefirstcharacterofaparticularline.int[][]circular_shifts_Twodimensionalarraythatstorestheoriginallinenumberandallofitscircularshifts,storedasindexesoftheoriginalcharacterarrayint[][]alphabetized_TwodimensionalarraythatstoresalphabetizedcircularshiftsKWIC-MainProgram/SubroutinewithSharedDataDataPresentationTheinputfunctioniscalledtoreadandparsethelinesfromaninputfileandrepresentsitbymeansofthecharacter(chars_)andlineindex(line_index_)array.(首先调用input函数来读取和解析输入文件并将其写在chars_和line_index_数组中)ThemainfunctioncallsthecircularShiftfunction,whichproducescircularshiftsofeachparticularlineandstoresitinthecircularshiftsarray(circular_shifts_).(然后调用circularShift函数,产生移位结果并写入circular_shifts_数组中)Themainfunctioncallsthealphabetizefunction,whichsortscircularshiftsalphabetically.Theresultisstoredinthealphabetizedarray(alphabetized_).(然后调用alphabetize函数对其进行排序,结果写入alphabetized_数组中)Finally,themainfunctioncallstheoutputfunction,whichprintsthesortedlines.(最后调用output函数,输出结果)ProcessKWIC-MainProgram/SubroutinewithSharedDataKWIC:KeyAlgorithm-inputTheformatofrawdataisasfollows.Linesareseparatedbythelineseparatorcharacter(s)(onUnix'\n',onWindows'\r\n').Eachlineconsistsofanumberofwords.Wordsaredelimitedbyanynumberandcombinationofthespacechracter('')andthehorizontaltabulationchracter('\t').Theentereddataisparsedinthefollowingway.Alllineseparatorsareremovedfromthedata,allhorizontaltabulationworddelimitersarereplacedbyasinglespacecharacter,andallmultipleworddelimitersarereplacedbyasinglespacecharacter.Thentheparseddataisrepresentedincoreastwoarrays.Thefirstarrayisachararray(char[]chars_),whichkeepsallwordssepratedbyasinglespacecharacter.Sinceweremovedlineseparatorsfromthedatathesecondintegerarray(int[]line_index_)keepsindexesofthechars_arraywherelinesstart.KWIC-MainProgram/SubroutinewithSharedDataKWIC:KeyAlgorithm-circularShiftcircularShiftfunctionprocessesthetwoarrayspreparedbyinputfunction.Itproducesallcircularshiftsofalllinesstoredincore.Acircularshiftisalinewherethefirstwordisremovedfromthebeginofalineandappendedontheendoftheline.Toobtainallcircularshiftsofalinewerepeatthisprocessuntilwecan'tobtainanynewlines.Werepresentacircularshiftofalineasapairofindices.Thefirstpartofthepairistheindexinthechars_array,wherethefirstwordoftheshiftedlinestarts(在_array中的index).Tobeabletodeterminetheboundariesoftheoriginalline,thesecondpartofthepairkeepstheindexoftheoriginallineinthelineindexarray(在_line_index中的index).Thus,allcircularshiftsarerepresentedasanarrayofsuchpairs,i.e.,astwodimensionalintegerarrayint[][]circular_shifts_.KWIC-MainProgram/SubroutinewithSharedDataAdvantages:Datacanberepresentedefficiently,sincecomputationscansharethesamestorage.(模块之间的数据共享)Distinctcomputationalaspectsareisolatedindifferentmodules(不同的计算功能被隔离在不同的模块中)Disadvantages:Achangeindatastorageformatwillaffectalmostallofthemodules.(对数据存储格式的变化将会影响几乎所有的模块)Changesintheoverallprocessingalgorithmandenhancementstosystemfunctionarenoteasilyaccommodated.(对处理流程的改变与系统功能的增强也很难适应,依赖于控制模块内部的调用次序)Thisdecompositionisnotparticularlysupportiveofreuse.(这种分解也难以支持有效的复用)KWIC-MainProgram/SubroutinewithSharedDataKWIC-AbstractDataTypes采用OO的思想,数据和作用在数据上的读写操作被封装为object,主程序调用这些object,形成控制流程;Dataisnolongerdirectlysharedbythecomputationalcomponents.(数据不再被构件直接共享,而是被封装在了Object中)Eachmoduleprovidesaninterfacethatpermitsothercomponentstoaccessdataonlybyinvokingproceduresinthatinterface.(每个对象提供了一个接口,允许其他对象通过该接口调用对该对象内封装的数据的操作)KWIC-AbstractDataTypesClassDiagram:

SystemStatics主控制程序“输入”对象“输出”对象“排序”对象“循环移位”对象“行数据存储”对象KWIC-AbstractDataTypesInputobject(负责从输入文件中读取数据并将其存储在LineStorage对象中)LineStorageobject(存储和处理字符、单词、行)CircularShifterobject(负责对LineStorage对象中存储的数据进行循环移位)Alphabetizerobject(负责对循环移位后得到的数据进行排序)Outputobject(负责打印输出排序后的数据)Mastercontrolobject(主控制对象:负责控制其他各对象中方法的调用次序)KWIC-AbstractDataTypesSequenceDiagram:SystemDynamics主控制程序“输入”对象“输出”对象“排序”对象“循环移位”对象“行数据存储”对象KWIC-AbstractDataTypesClassKWIC

//主对象KWIC构造五个对象实例

LineStoragelines=newLineStorage();Inputinput=newInput();CircularShiftershifter=newCircularShifter();Alphabetizeralphabetizer=newAlphabetizer();Outputoutput=newOutput();//然后分别调用这五个对象实例的某些方法

input.parse(file,lines);shifter.setup(lines);alphabetizer.alpha(shifter);output.print(alphabetizer);KWIC-AbstractDataTypesAdvantages:Bothalgorithmsanddatarepresentationscanbechangedinindividualmoduleswithoutaffectingothers.(某一构件的算法与数据结构的修改不会影响其他构件)Reuseisbettersupportedthaninthefirstsolutionbecausemodulesmakefewerassumptionsabouttheotherswithwhichtheyinteract.(构件之间依赖性降低,提高了复用度)KWIC-AbstractDataTypesDisadvantages:Thesolutionisnotparticularlywell-suitedtoenhancements.(不是特别适合功能的扩展)Foraddingnewfunctionstothesystem,theimplementormusteithermodifytheexistingmodulesoraddnewmodulesthatleadtoperformancepenalties.(为了增加新功能,要么修改已有的模块,要么就加入新的模块)从架构观点看,OO优于MainProgram/Subroutine依赖减少

易于理解

易于维护

易于复用KWIC-M/S

vs

AbstractDataTypesUsesapipelinesolution.(使用管道-过滤器风格)Therearefourfilters:input,shift,alphabetize,andoutput.(四个过滤器:输入、移位、排序、输出)Eachfilterprocessesthedataandsendsittothenextfilter.(每个过滤器处理数据,然后将结果送至下一个过滤器)Controlisdistributed:eachfiltercanrunwheneverithasdataonwhichtocompute.(控制机制是分布式的:只要有数据传入,过滤器即开始工作)Datasharingbetweenfiltersisstrictlylimitedtothattransmittedonpipes.(过滤器之间的数据共享被严格限制在管道传输)KWIC-PipesandFiltersSolution:PipesandFiltersFilters:Inputfilter(“输入”过滤器:从数据源读取输入文件,解析格式,将行写入输出管道)CircularShifterfilter(“循环移位”过滤器)Alphabetizerfilter(“排序”过滤器)Outputfilter(“输出”过滤器)Pipe:in_cspipecs_alpipeal_oupileKWIC-PipesandFiltersPipePipe

-reader_:PipeReader-writer_:PipedWriter+read(outc:int)+write(c:int)+closeReader()+closeWriter()KWIC-PipesandFiltersimportjava.io.PipedReader;importjava.io.PipedWriter;importjava.io.IOException;publicclassPipe{ privatePipedReaderreader_; privatePipedWriterwriter_; publicPipe()throwsIOException{ writer_=newPipedWriter(); reader_=newPipedReader();/letthispipedwritertobeconnectedtothepipedreader writer_.connect(reader_);

}.//Writeschartothepipedoutputstream publicvoidwrite(intc)throwsIOException{ writer_.write(c); } //

Readsthenextcharacterofdatafromthispipedstream publicintread()throwsIOException{ returnreader_.read(); } publicvoidcloseWriter()throwsIOException{ writer_.flush(); writer_.close(); } publicvoidcloseReader()throwsIOException{ reader_.close(); }}FilterFilter

input_:Pipeoutput_:PipeFilter()start()run()stop()transform()publicabstractclassFilterimplementsRunnable{ protectedPipeinput_; protectedPipeoutput_; privatebooleanis_started_=false;

publicFilter(Pipeinput,Pipeoutput){ input_=input; output_=output; } publicvoidstart(){ if(!is_started_){ is_started_=true; Threadthread=newThread(this); thread.start(); } } publicvoidstop(){ is_started_=false;

}

publicvoidrun(){ transform();

}/* *Thismethodtransformsthedatafromtheinputpipeandwritesthe *transformeddataintooutputpipe.

*/ abstractprotectedvoidtransform();}KWIC-PipesandFilters ... FileInputStream

in=newFileInputStream(file); Pipein_cs=newPipe();//createthreeobjectsofPipe Pipecs_al=newPipe();//andoneobjectoftype Pipeal_ou=newPipe();//FileInputStream

Inputinput=newInput(in,in_cs); CircularShiftershifter=newCircularShifter(in_cs,cs_al); Alphabetizeralpha=newAlphabetizer(cs_al,al_ou); Outputoutput=newOutput(al_ou);//outputtoscreen input.start(); shifter.start(); alpha.start(); output.start(); ...对象之间没有直接耦合KWIC-PipesandFilters对比Mainprogram/subroutine风格实现很多很复杂的数据依赖!!!KWIC-PipesandFilters对比OO风格实现

//主对象KWIC构造五个对象实例

LineStoragelines=newLineStorage();Inputinput=newInput();CircularShiftershifter=newCircularShifter();Alphabetizeralphabetizer=newAlphabetizer();Outputoutput=newOutput();//然后分别调用这五个对象实例的某些方法

input.parse(file,lines);shifter.setup(lines);alphabetizer.alpha(shifter);output.print(alphabetizer);input对象依赖lines对象Shifter对象依赖lines对象alphabetizer对象依赖Shifter对象output对象依赖alphabetizer对象除此之外,还有一些间接依赖关系!KWIC-PipesandFiltersPipesandFilters的优势Itmaintainstheintuitiveflowofprocessing.(过程流非常直观)Itsupportsreuse(支持复用!!)Itsupportseaseofmodification,sincefiltersarelogicallyindependentofotherfilters.(容易修改!!)Eachfiltercanfunctioninisolation(providedupstreamfiltersproducedataintheformitexpects).(过滤器的功能相互隔离)Newfunctionsareeasilyaddedtothesystembyinsertingfiltersattheappropriatepointintheprocessingsequence.(新功能容易加入)KWIC-PipesandFiltersPipesandFilters的不足Itisvirtuallyimpossibletomodifythedesigntosupportaninteractivesystem.(无法支持交互式系统,局限性较大!)Forexample,inordertodeletealine,therewouldhavetobesomepersistentsharedstorage,violatingabasictenetofthisapproach.Thesolutionisinefficientintermsofitsuseofspace,sinceeachfiltermustcopyallofthedatatoitsoutputports.(空间复杂性高)KWIC-PipesandFilters思考:有没有其他更好的架构风格呢?Event

system?本节内容KWIC案例分析1图书借阅系统案例分析230

该系统向西安电子科技大学的师生提供图书借阅服务;有南校区和北校区两个图书存储地点(即2个分馆),图书索引应能查询所有的分馆的信息;分馆之间不支持馆际借阅;学生一次可借阅16本书,1个月内归还;教师一次可借阅任何数量的书,2个月内归还;学生和教师均可以预定图书,如预定图书处于可借阅状态,预定有效期为1天;如果预定的图书正处于被借出状态,系统需要向借阅者发出一封email进行提醒;如果借阅的图书过期2周、6周、10周,则向借阅者发出email进行提醒;当过期未还时,该借阅者无法再借阅其他图书,而且当过期超过1个月后,每本书每天罚款1元;如果有未付清的罚款,借阅者也无法再借阅其他图书;除了图书之外,还提供杂志的借阅服务,借阅规则同图书相同。31图书借阅系统-高校图书馆系统需求32表现层业务逻辑层数据层用户管理可借阅物品管理预定管理借阅管理用户借阅权限管理归还管理系统自动监控…教师学生图书管理员图书检索付款管理HTMLCSSJavaScript图书借阅系统-架构设计OO+事件系统33用户“预定管理”服务通知通知预定事件通知用户“借阅管理”服务过期事件通知用户“系统自动监控”服务修改权限通知“权限管理”服务如果预定图书处于被借出状态如果预定图书被归还图书借阅系统-架构设计

该系统为某连锁书店的图书借阅系统,向书店会员提供图书借阅服务;该市共有分布在不同地点的5家连锁书店,图书索引应能查询所有分店的信息;分店之间不支持跨店借阅与归还;普通会员一次可借阅10本书,3个月内归还;高级会员一次可借阅任何数量的书,6个月内归还;所有会员均可以预定图书,如预定图书处于可借阅状态,预定有效期为1周;如果预定的图书正处于被借出状态,系统会向借阅者发出一封email进行提醒;如果借阅的图书过期,系统将从过期之日起,每天向借阅者发出email进行提醒;当过期未还时,该借阅者无法再从任何分店借阅其他图书,而且当过期超过1周后,每本书每天罚款1元,从会员押金中自动扣除;如果有未付清的罚款,借阅者也无法再借阅其他图书;此外,还为高级会员提供杂志的借阅服务。34图书借阅系统-连锁书店借阅系统需求“基于规则的系统”风格35“权限管理”服务“用户管理”服务图书借阅系统-架构设计Consistsofalargenumberofitemsstoredatoneormorelocations;(包含多个可借用的项目和多个存储位置)Alibraryhascustomers;(有多个客户)Fourprimaryactionswhichareperformed:(主要操作)1)Removalofanitemfromthelibrarybyacustomer(用户从库中借出某些项目)2)Acustomercanreturnanitem.(用户向库还回某些项目)3)Allowcustomerstosearchforagivenitembykeywords;(允许用户通过关键字查询库中所拥有的可借阅项目)4)Auxiliaryoperations:(其他辅助操作)Addinganddeletingcustomers(注册或删除用户

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论