敏捷软件开发.ppt

上传人:牧羊曲112 文档编号:6417762 上传时间:2023-10-29 格式:PPT 页数:111 大小:1.38MB
返回 下载 相关 举报
敏捷软件开发.ppt_第1页
第1页 / 共111页
敏捷软件开发.ppt_第2页
第2页 / 共111页
敏捷软件开发.ppt_第3页
第3页 / 共111页
敏捷软件开发.ppt_第4页
第4页 / 共111页
敏捷软件开发.ppt_第5页
第5页 / 共111页
点击查看更多>>
资源描述

《敏捷软件开发.ppt》由会员分享,可在线阅读,更多相关《敏捷软件开发.ppt(111页珍藏版)》请在三一办公上搜索。

1、敏捷软件开发,摘要,IntroductionAgile Development Agile Design,摘要,IntroductionAgile DevelopmentAgile Design,Introduction,Robert C.Martin:“Agile Software Development Principles,Patterns,and Practices”,Prentice Hall(October 25,2002),Jolt Award2003,Introduction,Robert C.Martin,“Designing Object Oriented C+Applic

2、ations using the Booch Method”,1995“Pattern Languages of Program Design 3”,1997,“More C+Gems”,1999,“Extreme Programming in Practice”,2003“UML for Java Programmers”,2003,Uncle Bob,Agile 敏捷,敏捷开发是一种面临迅速变化的需求快速开发软件的能力。提供必要的纪律和反馈的实践-practice保持软件灵活、可维护的设计原则-principle针对特定问题的设计模式-pattern适应变化和以人为中心,迭代、循序渐进,T

3、he Agile Alliance 敏捷联盟,The Manifesto of the Agile Alliance 敏捷联盟宣言,2001,We are uncovering better ways of developing softwareby doing it and helping others do it.Through this workwe have come to value:Individuals and interactions over processes and toolsWorking software over comprehensive documentatio

4、nCustomer collaboration over contract negotiationResponding to change over following a plan,Kent Beck,Alistair Cockburn,Robert C.Martin,etc.,敏捷联盟宣言,个体和交互胜过过程和工具可以工作的软件胜过面面俱到的文档客户合作胜过合同谈判响应变化胜过遵循计划,Principles,我们最优先要做的是通过尽早的、持续的交付有价值的软件来使客户满意。即使到了开发的后期,也欢迎改变需求。敏捷过程利用变化来为客户创造竞争优势。经常性地交付可以工作的软件,交付的间隔可以从

5、几个星期到几个月,交付的时间间隔越短越好。,Principles,在整个项目开发期间,业务人员和开发人员必须天天都在一起工作。围绕被激励起来的个体来构建项目。给他们提供所需的环境和支持,并且信任他们能够完成工作。在团队内部,最具有效果并富有效率的传递信息的方法,就是面对面的交谈。,Principles,工作的软件是首要的进度度量标准。敏捷过程提倡可持续的开发速度。责任人、开发者和用户应该能够保持一个长期的、恒定的开发速度。不断地关注优秀的技能和好的设计会增强敏捷能力。,Principles,简单使未完成的工作最大化的艺术是最根本的。最好的构架、需求和设计出于自组织团队。每隔一定时间,团队会在如

6、何才能更有效地工作方面进行反省,然后相应地对自己的行为进行调整。,Agile Processes,SCRUMCrystalFeature Driven Development 特征驱动软件开发Adaptive Software Development 自适应软件开发eXtreme Programming(XP)极限编程,摘要,IntroductionAgile Development Agile DesignDesign Patterns,Agile Development,Extreme Programming(XP,极限编程)是一种轻量级的软件开发方法,它使用快速的反馈,大量而迅速的交流,

7、经过保证的测试来最大限度的满足用户的需求。XP强调用户满意,开发人员可以对需求的变化作出快速的反应。XP强调team work。项目管理者,用户,开发人员都处于同一个项目中,他们之间的关系不是对立的,而是互相协作的,具有共同的目标:提交正确的软件。,Extreme Programming,XP强调4个因素:交流(communication),XP要求程序员之间以及和用户之间有大量而迅速的交流简单(simplicity),XP要求设计和实现简单和干净反馈(feedback),通过测试得到反馈,尽快提交软件并根据反馈修改勇气(courage),勇敢的面对需求和技术上的变化,Extreme Prog

8、ramming,XP特别适用于需求经常改变的领域,客户可能对系统的功能并没有清晰的认识,可能系统的需求经常需要变动。XP也适用于风险比较高的项目,当开发人员面对一个新的领域或技术时,XP可以帮助减低风险XP适用于小的项目(人员上),人员在2-12人之间,XP不适用于人员太多的项目,Practices of XP,客户作为团队成员用户素材 user stories短周期交付迭代计划发布计划验收测试结对编程 pair programming,Practices of XP,测试驱动的开发方法 Test-Driven Development集体所有权持续集成可持续的开发速度开放的工作空间计划游戏 p

9、lanning game简单的设计重构 Refactoring隐喻 Metaphor:将整个系统联系在一起的全局视图,摘要,IntroductionAgile Development Agile Design,What is Design?,“After reviewing the software development life cycle as I understood it,I concluded that the only software documentation that actually seems to satisfy the criteria of an engineer

10、ing design is the source code listings.”-Jack Reeves,Design Smells,Rigidity 僵化性 难于修改Fragility 脆弱性 一改便乱Immobility 牢固性 难于重用Viscosity 粘滞性 做好事难Needless Complexity 不必要的复杂性Needless Repetition 不必要的重复Opacity 晦涩性,The“Copy”Program,Initial Design,void copy()int c;while(c=RdKbd()!=EOF)WrtPrt(c);,Requirement cha

11、nges,bool ptFlag=false;/remember to reset this flagvoid Copy()int c;while(c=(ptFlag?RdPt():RdKbd()!=EOF)WrtPrt(c);,Requirement changes again!,bool ptFlag=false;bool punchFlag=false/remember to reset these flagsvoid Copy()int c;while(c=(ptFlag?RdPt():RdKbd()!=EOF)punchFlag?WrtPunch(c):WrtPrt(c);,Agil

12、e design of the“copy”example,int RdKbd();void WrtPrt(int);const int EOF=-1;class Reader public:virtual int read()=0;class KeyboardReader:public Reader public:virtual int read()return RdKbd();KeyboardReader GdefaultReader;void Copy(reader,Agile developers,Knew what to do becauseDetect the problem by

13、following agile practices;Diagnose the problem by applying design principlesSolve the problem by applying the appropriate design patternThe interplay between these three aspects of software development is the act of design.,A more complex example:Multi-panel interactive systems,问题简单方案结构化的方案面向对象的方案讨论

14、,28,Multi-panel interactive systems,问题:业务流程每个会话(session)须经历多个步骤当前步骤显示panel(对话框),获取用户输入(选择),若输入错,给提示,直至正确;依据输入进行处理并转入下一步骤(转入哪个步骤可能依赖于用户的输入);对话界面例如航空订票,29,29-23,Institute of Computer SoftwareNanjing University,状态转换图,设计要点,图可能很大图可能变化要考虑复用,32,软件设计之难在于多种(可能冲突)的需求之间的均衡取舍,A Simple-minded solution,33,A Simpl

15、e-minded solution,问题“Goto”!本质:转换图结构分散地hardwired到各个模块的算法中若增加状态或改动流程?如何复用?,34,A functional,top-down solution,好,我们消除goto,并将流程独立出来,放到一个函数中transition(state,choice),35,Top-down decomposition,The top,Critique,Fragileness,42,增加状态怎样?,如何在不同应用间复用?,object-oriented architecture,Law of inversionIf your routines e

16、xchange too many data,put your routines in your data.,State as a class,Use inheritance and deferred class,The system?An ADT,not a“main”function,29-23,Institute of Computer SoftwareNanjing University,54,讨论,Focus on data abstraction“Forget”the“main”function of the system,resist the constant temptation

17、 to ask“What does the system do?”Law of inversionRealworldliness is not a significant difference between OO and other approaches;what counts is how we model the world,摘要,IntroductionAgile DevelopmentAgile Designdesign principlesDesign Patterns,Design Principles,SRP(The Single-Responsibility Principl

18、e)单一职责原则OCP(The Open-Closed Principle)开放-封闭原则LSP(The Liskov Substitution Principle)Liskov替换原则DIP(The Dependency-Inversion Principle)依赖倒置原则ISP(The Interface-Segregation Principle)接口隔离原则,SRP 单一职责原则,A class should have only one reason to change.就一个类而言,应该仅有一个引起它变化的原因。What is a Responsibility?A reason fo

19、r change 变化的原因。每个职责都是变化的一个轴线,当需求变化时,该变化会反映为职责的变化。An axis of change is an axis of change only if the changes actually occur.变化的轴线仅当变化实际发生时才具有真正的意义。,Example,Example:applying SRP,Example:SRP violation,interface Modem public void dial(String pno);public void hangup();public void send(char c);public char

20、 recv();,connectionmanagement,datacommunication,Example,Separated modem interface,OCP 开放-封闭原则,Software entities(classes,modules,functions,etc.)should be open for extension,but closed for modification.软件实体(类、模块、函数等)应该是可以扩展的,但是不可修改的。OCP is the heart of OO design!,OCP Description,Two primary attributes

21、:Open for extension:the behavior of the module can be extendedClosed for modification:extending the behavior of a module does not result in changes to the source or binary code of the module.本质:不改源码,改行为Is it possible?,Abstraction is the key!,Client is neither open nor closed,Strategy Pattern,Client

22、is both open and closed,Template Method Pattern,A clear separation of generic functionality from the detailed implementation of that functionality,Heuristics,OCP是面向对象设计的核心所在!灵活性、可重用性、可维护性使用OOPL不代表遵循了OCP肆意抽象亦不是一个好主意100%的封闭不可能,必须有策略地对待这个问题。对程序中呈现出频繁变化的那些部分做出抽象,拒绝不成熟的抽象和抽象本身一样重要。,LSP:Liskov替换原则,Subtype

23、s must be substitutable for their base types.子类型必须能够替换掉它们的基类型。If for each object o1 of type S there is an object o2 of type T such that for all programs P defined in terms of T,the behavior of P is unchanged when o1 is substituted for o2 then S is a subtype of T.Liskov88 若对每个类型S的对象o1,都存在一个类型T的对象o2,使

24、得在所有针对T编写的程序P中,用o1代替o2后,程序P行为功能不变,则S是T的子类型。,LSP Violation(I),struct Shape enum ShapeType square,circle itsType;Shape(ShapeType t):itsType(t);struct Circle:public Shape Circle():Shape(circle);void Draw()const;struct Square:public Shape Square():Shape(circle);void Draw()const;,void DrawShape(const Sha

25、pe&s)if(s.itsType=Shape:square)static_cast(s).draw()else if(s.itsType=Shape:circle)static_cast(s).draw(),RTTI(运行时类型识别),LSP Violation(II),class Rectangle public:void SetWidth(double w)itsWidth=w;void SetHeight(double h)itsHeight=h;private:double itsWidth;double itsHeight;,IS-A Relationship,LSP Violat

26、ion(II),void Square:SetWidth(double w)Rectangle:SetWidth(w);Rectangle:SetHeight(w):void Square:SetHeight(double w)Rectangle:SetWidth(w);Rectangle:SetHeight(w):,void f(Rectangle/call Rectangle:SetWidth,:Square,Violated!,LSP Violation(II),class Rectangle public:virtual void SetWidth(double w)itsWidth=

27、w;virtual void SetHeight(double h)itsHeight=h;private:double itsWidth;double itsHeight;,Are Rectangle and Square self-consistent?,void g(Rectangle,:Square,True or false?,Violated!,The real problem,Validity is not intrinsic!有效性并非本质属性模型的有效性只能通过它的客户程序来表现。IS-A is about Behavior Behaviorally,a Square is

28、not a Rectangle.Recall DbC principle about inheritancePrecondition 更弱;Postcondition 更强,The real problem,Rectangle:SetWidth(double w)的后置条件Postcond:(itsWidth=w)&(itsHeight=old.itsHeight)但是Square:SetWidth(double w)不能满足该条件可以通过编写单元测试的方法来指定契约,Heuristics and Conventions,Violation 1:Degenerate functions in

29、derivatives 派生类中的退化函数Violation 2:Throwing exceptions from derivatives 从派生类中抛出异常,public class Base public void f()/*some code*/Public class Derived extends Base public void f(),LSP,One of the enablers of the OCP。LSP是使OCP成为可能的主要原则之一。It is the substitutability of subtypes that allows a module,expressed

30、 in terms of a base type,to be extensible without modification.正是子类型的可替换性才使得使用基类类型的模块在无需修改的情况下就可以扩展。,DIP 依赖倒置原则,High level modules should not depend on low-level modules.Both should depend on abstractions.高层模块不应该依赖于低层模块,二者都应该依赖于抽象。Abstractions should not depend on details.Details should depend on ab

31、stractions.抽象不应该依赖于细节,细节应该依赖于抽象。Inversion:相对于结构化方法而言,Booch:“all well structured OO architectures have clearly defined layers,with each layer providing some coherent set of services through a well-defined and controlled interface.”,Laying,Unfortunate!,Laying,Inverted layers,also an inversion of inter

32、face ownership:客户拥有抽象接口,服务者则从这些抽象接口派生。,Hollywood principle:“dont call us,well call you.”低层模块实现在高层模块中声明并被高层模块调用的接口。,Heuristic,“Depend on abstractions”依赖于抽象不应该依赖于具体类程序中所有的依赖关系都应该终止于抽象类或者接口According to it:任何变量都不应该持有一个指向具体类的指针或引用任何类都不应该从具体类派生任何方法都不应该覆写它的任何基类中的已经实现了的方法例外:可以依赖稳定的具体类,比如String,DIP,依赖关系的倒置正是

33、好的面向对象设计的标志所在。如果程序的依赖关系是倒置的,它就是面向对象的设计,否则就是过程化的设计。DIP是实现许多OO技术所宣称的好处的基本低层机制。它的正确应用对于创建可重用的框架来说是必须的。,ISP 接口隔离原则,Clients should not be forced to depend on methods that they do not use.不应该强迫客户依赖于它们不用的方法。Deals with the disadvantage of“fat”interfaces whose interfaces are not cohesive.处理接口不是内聚的胖接口的缺点,Exam

34、ple,class Door public:virtual void Lock()=0;virtual void Unlock()=0;virtual bool IsDoorOpen()=0;,class Timer public:void Register(int timeout,TimeClient*client);,class TimerClient public:virtual void TimeOut()=0;,common door!,How about a timed door?,Interface Pollution,But not all varieties of Door

35、need timing!,Separate Interfaces,Solution 1:adapter 使用委托分离接口,class TimedDoor:public Door public:virtual void DoorTimeOut(int timeoutId);Class DoorTimerAdapter:public TimeClient pubic:DoorTimerAdapter(TimedDoor,Separate Interfaces,Separate Interfaces,Solution 2:multiple inheritance,class TimedDoor:pu

36、blic Door,publid TimerClient public:virtual void TimeOut(int timeoutId);,How to design Packages?,在向包中分配类时应该依据什么原则?应该使用什么设计原则来管理包之间的关系?包的设计应该先于类呢(自顶向下)?还是类的设计应该先于包(自底向上)?如何实际表现出“包”?C+?Java?某种开发环境?包创建好后,应当将它们用于何种目的?,粒度:包的内聚性原则,REP(The Reuse-Release Equivalence Principle),重用发布等价原则,重用的粒度就是发布的粒度。CRP(The

37、Common-Reuse Principle),共同重用原则,一个包中的所有类应该是共同重用的。CCP(The Common-Closure Principle),共同封闭原则,包中的所有类对于同一类性质的变化应该是共同封闭的。,REP,当你重用一个类库时,对这个类库的作者有什么期望呢?-维护?通知修改?REP指出,一个包的重用粒度(granule of reuse)可以和发布粒度(granule of release)一样大。所重用的任何东西都必须同时被发布和跟踪。可重用的包必须包含可重用的类!可重用性不是唯一标准,也要考虑重用这些软件的人。,CRP,一个包中的所有类应该是共同重用的,如果重

38、用了包中的一个类,那么就要重用包中的所有类。趋向于共同重用的类应该属于同一个包。相互之间没有紧密联系的类不应该在同一个包中。jar的修改和发布,CCP,包中的所有类对于同一类性质的变化应该是共同封闭的。一个变化若对一个包产生影响,则将对该包中的所有类产生影响,而对于其它的包不造成任何影响。回顾下SRP,OCP把可能由于同样的原因而更改的所有类共同聚集在同一个地方。,稳定性:包的耦合性原则,ADP(The Acyclic-Dependencies Principle),无环依赖原则,在包的依赖关系图中不允许存在环。SDP(The Stable-Dependencies Principle),稳定

39、依赖原则,朝着稳定的方向进行依赖。SAP(The Stable-Abstractions Principle),稳定抽象原则,包的抽象程度应该和其稳定程度一致。,ADP,“晨后综合症”每周构建消除依赖环DAG,ADP,具有依赖环的包图发布MyTasks测试MyDialogs,解除依赖环,方法1:使用依赖倒置原则,解除依赖环,方法2:新创建一个彼此都依赖的包,将依赖的类移到这个新包中,Jitter和增长,Heuristic,不能自顶向下设计包的结构包结构是随着系统的增长、变化而逐步演化的包的依赖关系图和描绘应用程序的功能之间几乎没有关系,相反,它们是应用程序可构建性的映射图。,SDP,不要依赖不

40、稳定的包对于任何包而言,如果期望它是可变的,就不应该让一个难以更改的包依赖于它,否则,可变的包同样也难以更改。,稳定,不稳定,稳定性度量,(Ca)输入耦合度:指处于该包的外部并依赖于该包内的类的类的数目(Ce)输出耦合度:指处于该包的内部并依赖于该包外的类的类的数目不稳定性I:0,1I=0 最稳定I=1 最不稳定SDP规定一个包的I度量值应该大于它所依赖的包的I度量值(即I度量值应该顺着依赖的方向减少),稳定性度量,Pa,q,r,Pb,s,Pc,t,u,Pd,v,Pc:Ca=3,Ce=1,I=1/4,稳定 vs.不稳定,并非所有的包都应该是稳定的,理想的包配置,违反了SDP,思考题:HOW TO?,i=1,i=1,i=0,稳定 vs.不稳定,DIP,SAP,包的抽象程度应该和其稳定性一致。一个稳定的包应该也是抽象的,这样它的稳定性就不会使其无法扩展一个不稳定的包应该是具体的,因为它的不稳定性使得其内部的具体代码易于更改。,依赖应该朝着抽象的方向进行!,Remember,As with all principles,care must be taken not to overdo it.,作业(本次作业不用提交),查看Java中Collection框架或Concurrent框架的源代码,考察一个优秀的框架是如何遵循面向对象的设计原则的。,

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 生活休闲 > 在线阅读


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号