版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、Outline1Why and what is software design?Software design principles Design patternsModel-View-ControllerSummaryProgrammers ApproachSkip requirements engineering and design phases;start writing code2Why this programmers approach?Design is a waste of timeWe need to show something to the customer real q
2、uickWe are judged by the amount of LOC/monthWe expect or know that the schedule is too tight3A Case Study4Travel System階段1. 基本原型系統(tǒng)階段2. 各種折扣策略階段3. 基于服務(wù)的集成5Phase I6UIDatabaseUI7UIDatabase89Phase II10login21login22login2Xlogin32login31login3XMagic Number11The complicated Login Process The hard-coded po
3、lices 12Phase III: The configurable policies13Hard-coded RulesExternalized Policies14Point to PonderThe longer you postpone coding, the sooner youll be finished.15Software DesignThe process of defining the architecture, components, interfaces, and other characteristics of a system or component.The r
4、esults of that process.IEEE Standard Glossary of Software Engineering Terminology, IEEE std 1990.16The beginning of wisdom for a software engineer is to recognize the difference between getting a program to work, and getting it right.” M.A. Jackson 75Software DesignDesign process moves from a “big p
5、icture” view of software to a more narrow view that defines the detail required to implement a system.ArchitectureSubsystemCommunication mechanismComponents External, internal and user interfaces17Design PrinciplesKISS = Keep It Simple StupidModularitySeparation of ConcernDesign for CHANGEDesign for
6、 REUSE19Design Principles1996199420101. Simple is Beauty“There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more
7、 difficult. ” C. A. R. Hoare2021“You know youve achieved perfection in design, not when you have nothing more to add, but when you have nothing more to take away”- Antoine de Saint-ExuperySmalltalkApple Lisa“Everything should be made as simple as possible, but no simpler”- Albert Einstein“Simplicity
8、 is the ultimate sophistication”- Lenonardo Da Vinci2. ModularizationA mechanism for enhancing flexibility and comprehensibilityDividing complex system into simpler componentsComponents should be highly cohesive and loosely-coupledInformation HidingThe modules are identified by System descriptionDes
9、ign decisionsSystem level decisions2223Three Papers by David Parnas“On the Criteria To Be Used in Decomposing Systems into Modules”Comm. ACM 15, 12 (Dec. 1972), 1053-1058“On a Buzzword: Hierarchical Structure”IFIP Congress 74.North Holland Publishing Company, 1974 pp. 336-339“On the design and devel
10、opment of program families”IEEE Trans. On SE., vol. SE-2, pp.1-9, Mar. 1976ModularizationExpected benefitsDevelopment can be more easily plannedSoftware increments can be defined and deliveredChanges can be more easily accommodatedTesting and debugging can be conducted more efficientlyLong-term main
11、tenance can be conducted without serious side effects24Modularization25Modularitystructural criteria which tell us something about individual modules and their interconnectionscohesion and couplingcohesion: the glue that keeps a module togethercoupling: the strength of the connection between modules
12、26Strong cohesion & Weak couplingSimpler communicationSimpler correctness proofsChanges influence other modules less oftenReusability increasesComprehensibility improves27Simple InterfaceMany decisions are strongly related and interdependent Concentrate on different aspects of a problem separately e
13、.g. software qualities, development process, operating constraintsSeparation may be based on time, qualities, views, size, level of details etc.283. Separation of ConcernsDivide and ConquerCrosscutting ConcernsConcerns whose implementation cuts across a number of program components.ConcernImplementa
14、tionAObject 1BObject 2CObject 3DObject 4EObject 1,2,329Crosscutting ConcernsThis results in problems when changes to the concern have to be made the code to be changed is not localized but is in different places across the system.Crosscutting concerns lead to tangling and scattering. 30Problems like
15、 Logging is not modularized Where is logging in org.apache.tomcatRed shows lines of code that handle loggingNot in just one placeNot even in a small number of places31Separation of ConcernsSoftware should be organized so that each program element does one thing and one thing only.Each program elemen
16、t should therefore be understandable without reference to other elements.Program abstractions (subroutines, procedures, objects, etc.) support the separation of concerns. 32Change is inevitable and frequent due tobugs-eliminationchanging user requirementstechnology evolutionChange in the software pr
17、oduct as well as the development processStrategy is to consider the likely changes as part of the system designIsolate likely changes in specific portions of software such that changes will be restricted to small portionsdevelop reusable modules, design334. Anticipation of ChangesDesigning software
18、for ease of extension and contractionDavid Parnas, ICSE78“When we were first taught how to program, we were given a specific program and told to write one program to do that job.Today, the software designer should be aware that he is not designing a single program but a family of programs We want to
19、 exploit the commonalities, share code, and reduce maintenance costs Engineers are taught that they must try to anticipate the changes that may be made and are shown how to achieve designs that can easily be altered when these anticipated changes occur. ”34 (1) They may run on different hardware con
20、figuration. (2) They may perform the same functions but differ in the format or the input and output data. (3) They may differ in certain data structures or algorithms because of differences in the available resources. (4) They may differ in some data structures of algorithms because of differences
21、in the size of the input data sets or the relative frequencies of certain events. (5) Some users may require only a subset of the services or features that other users need. These less demanding users may demand that they not be forced to pay for the resources consumed by the unneeded features. ”35D
22、esigning software for ease of extension and contractionDavid Parnas, ICSE78Design with and for reuseTo avoid “reinventing the wheel”Software is expensive. Reuse of software assets is essential to increase ROI (return on investment)Lower production and maintenance costFaster deliveryIncreased quality
23、Software reusable assetsReq. specs, design spec., code, test casesProblem solution, design solutionToolsProcessExperiences and best practices365. ReuseThe Key to Modern IndustryHandcraft Assembly line1913-14, Ford Motor Company, mass productionInterchangeabilityReinventing workflow and job descripti
24、onsBenefits: Reduced unit-cost Affordable Ford Model TConsistent quality Improved productivity 37Some Reuse FactsHitachi: reduced number of late projects from 72% to 7% in 4 yearsToshiba: improved productivity 3 times in 9 years, 50% code reuse; reduced error rate from 7-20 per 1 KLOC to 2-3Fijitsu:
25、 improved productivity by 2/3, reduced error rate by factor of 10NEC: increased productivity by 26% to 91%HP: shortened time-to-market by factor of 4, reduced error rate by factor of 1038Reuse granularitiesApplication system reuseReuse the whole of the application as COTS (Commercial-Off-The-Shelf)
26、or as family applicationsComponent reuseReuse parts of the application ranging from sub-systems to single objectsFunction reuseReuse as a single well-defined function. e.g., standard graphics and mathematical libraries.39ReuseWhat makes a good Object-Oriented Design?4041“OO has been tied to a variet
27、y of complex languages. Instead of teaching people that O-O is a type of design, and giving them design principles, people have been taught that O-O is the use of a particular tool. We can write good or bad programs with any tool. Unless we teach people how to design, the languages matter very littl
28、e. The result is that people do bad designs with these languages and get very little value from them.” - David Parnas, 1995 Information HidingUse private members and appropriate accessors and mutators wherever possible. 42Public double speedPrivate double speed;Public double getSpeed () Return (Spee
29、d);Public void setSpeed (double newSpeed) speed = newSpeed;43Public void setSpeed (double newSpeed) if (newSpeed 0) sendErrorMessage (); . speed = newSpeed;Public void setSpeedInMPH (double newSpeed) speedInKPH = convert (newSpeed);Public void setSpeedInKPH (double newSpeed) speedInKPH = newSpeed;Pu
30、blic void setSpeed (double newSpeed) speed = newSpeed; notifyObservers ();PerformSide EffectsInternal RepresentationConstraintsOn ValuesFavor Composition over InheritanceInheritanceMethod of reuse in which new functionality is obtained by extending the implementation of an existing object. The gener
31、alization class (the superclass) explicitly captures the common attributes and methods.The specialization class (the subclass) extends the implementation with additional attributes and methods. CharacteristicsWhite box reuseSubclass may have to be changed if the implementation of super-class changes
32、Implementation inherited from super-class cannot be changed at runtime44Favor Composition over InheritanceComposition (aggregation, containment)Method of reuse in which new functionality is obtained by creating an object composed of other objects.The new functionality is obtained by delegating funct
33、ionality to one of the objects being composed. CharacteristicsContained objects are accessed by the containing class solely through their interfacesBlack-box reuse Separation of concerns, each class is focused on just one taskCan be defined dynamically at run-time 45Favor Composition over Inheritanc
34、e46Public class InstrumentedHashSet extends HashSet / The number of attempted element insertions private int addCount = 0; public InstrumentedHashSet (Collection c) super(c); public InstrumentedHashSet (int initCap, float loadFactor) super (initCap, loadFactor); public boolean add (Object o) addCoun
35、t+;return super.add(o); public boolean addAll (Collection c) addCount += c.size();return super.addAll (c); public int getAddCount() return addCount; Public static void main (String args) InstrumentedHashSet s = new InstrumentedHashSet(); s.addAll (Arrays.asList (new String “Snap”, “Crackle”, “Pop”);
36、 System.out.println (s.getAddCount();Expected results: 3Real output: 6 !InheritanceExampleJava.util.AbstractCollectionJava.util.AbstractSetJava.util.HashSetJava.util.AbstractCollection47Favor Composition over Inheritance48Public class InstrumentedSet implements Set private final Set s; private int a
37、ddCount = 0; public InstrumentedSet (Set s) this.s = s; public boolean add (Object o) addCount+;return s.add(o); public boolean addAll (Collection c) addCount += c.size();return s.addAll (c); public int getAddCount() return addCount; The class is very flexible and can wrap any preexisting Set object
38、List list = new ArrayList();Set s1 = new InstrumentedSet (new TreeSet(list);Int capacity = 7;Float loadFactor = .66f;Set s2 = new InstrumentedSet (new HashSet (capacity, loadFactor);CompositionExampleFavor Composition over InheritanceBoth composition and inheritance are important methods of reuse.In
39、heritance was overused in the early days of OO development.Over time weve learned that designs can be made more reusable and simpler by composition.The available set of composable classes can be enlarged using inheritance. 49Program to the Interface not implementationAn interface is the set of metho
40、ds one object knows it can invoke on another object the key to pluggabilityImplementation inheritance vs. Interface inheritenceImplementation inheritance (Class inheritance) an objects implementation is defined by anothers Interface inheritance (Subtyping) describes when one object can be used in pl
41、ace of another Interface inheriance mechanismC+: abstract classJava: Java interfaceAdvantagesLoose couplingReuse by interface matchingDynamic binding 5051ImaneuverableCarBoatSubmarinePublic interface IManeuverable public void left (); public void right (); public void forward (); public void reverse
42、 (); public void climb (); public void dive (); public void setSpeed (double speed); public void getSpeed ();Public class Carimplements IManeuverable ;Public class Boatimplements IManeuverable ;Public class Submarineimplements IManeuverable ;Public void travel (IManeuverable vehicle) vehicle.setSpeed (35.0); vehicle.forward (); vehicle.left (); vehicle.climb ();Interface Inheritance ExampleSummarySoftware design is a key activity in software lifecycle process. The goal is to create a model of software that will
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 海南鋪面租賃合同書(shū)電子版
- 合同產(chǎn)生質(zhì)量事故考核
- 2024高考政治一輪復(fù)習(xí)課時(shí)練16中國(guó)特色社會(huì)主義最本質(zhì)的特征含解析新人教版
- 2024年高考生物二輪復(fù)習(xí)第一篇專(zhuān)題6考向3生物的進(jìn)化和生物多樣性學(xué)案
- 完美國(guó)際黃昏圣殿裝備屬性、所需材料系列介紹(武器篇)投
- 2024購(gòu)買(mǎi)服務(wù)的合同協(xié)議書(shū)
- 2024新疆事業(yè)編制合同到期后單位可以選擇不續(xù)簽
- 2024機(jī)動(dòng)車(chē)輛保險(xiǎn)合同樣本
- 2024北京市豬肉入市場(chǎng)廠掛鉤合同范本
- 2024消防工程改造合同
- 20200310公園安全風(fēng)險(xiǎn)辨識(shí)清單
- 華中科技大學(xué)官方信紙
- 60立方油罐容積細(xì)表
- WI-QA-02-034A0 燈具成品檢驗(yàn)標(biāo)準(zhǔn)
- 農(nóng)業(yè)信息技術(shù) chapter5 地理信息系統(tǒng)
- 部編版六年級(jí)上語(yǔ)文閱讀技巧及解答
- 斯派克max操作手冊(cè)
- 項(xiàng)目四 三人表決器ppt課件
- 結(jié)合子的機(jī)械加工工藝規(guī)程及銑槽的夾具設(shè)計(jì)
- 林武樟 完整陽(yáng)宅講義 筆記版[方案]
- 《會(huì)滾的汽車(chē)》ppt課件
評(píng)論
0/150
提交評(píng)論