资源描述:
《软件需求分析与设计-简单实现》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、软件需求分析与设计-简单实现简单实现主要内容对可见性进行设计将设计映射为代码测试驱动开发和重构8/4/20212可见性设计对象之间的可见性为了使发送者对象能够向接收者对象发送消息,发送者必须具有接受者的可见性可见性是对象”看到”或者引用其他对象的能力与范围有关四种类型属性可见性-B是A的属性参数可见性-B是A中方法的参数局部可见性-B是A中方法的局部对象(不是参数)全局可见性-B具有某种方法的全局可见性8/4/20213从Register到ProductCatalog的可见性是必须的:Registerent
2、erItem(itemID,quantity):ProductCatalogdesc=getProductDesc(itemID)publicvoidenterItem(itemID,qty){...desc=catalog.getProductDesc(itemID)...}classRegister{...privateProductCatalogcatalog;...}8/4/20214属性可见性:RegisterenterItem(itemID,quantity):ProductCatalogdesc
3、=getProductDesc(itemID)publicvoidenterItem(itemID,qty){...desc=catalog.getProductDesc(itemID)...}classRegister{...privateProductCatalogcatalog;...}8/4/20215参数可见性2:makeLineItem(desc,qty)enterItem(id,qty)1:desc=getProductDesc(id)2.1:create(desc,qty):Register:
4、Sale:ProductCatalogsl:SalesLineItemmakeLineItem(ProductDescriptiondesc,intqty){...sl=newSalesLineItem(desc,qty);...}8/4/20216属性可见性的参数2:makeLineItem(desc,qty)enterItem(id,qty)2:desc=getProductDesc(id)2.1:create(desc,qty):Register:Sale:ProductCatalogsl:SalesL
5、ineItem//initializingmethod(e.g.,aJavaconstructor)SalesLineItem(ProductDescriptiondesc,intqty){...description=desc;//parametertoattributevisibility...}8/4/20217局部可见性:RegisterenterItem(itemID,quantity):ProductCatalogdesc=getProductDesc(itemID)enterItem(id,qt
6、y){...//localvisibilityviaassignmentofreturningobjectProductDescriptiondesc=catalog.getProductDes(id);...}实现局部可见性的两种方式:创建新的局部实例并将其分配给局部变量将方法调用返回的对象分配给局部变量8/4/20218将设计映射为代码将设计映射为代码类和接口的定义方法的定义由DCD创建类的定义DCD描述了类或接口的名称、超类、操作的特征标记以及类的属性,可以从类图直接生成类的定义从交互图创建方法交互图中
7、的一系列消息可以转化为方法定义中的一系列语句8/4/20219Java中的SaleLineItempublicclassSalesLineItem{privateintquantity;privateProductDescriptiondescription;publicSalesLineItem(ProductDescriptiondesc,intqty){...}publicMoneygetSubtotal(){...}}SalesLineItemquantity:IntegergetSubtotal()
8、:MoneyProductDescriptiondescription:Textprice:MoneyitemID:ItemID...1description8/4/202110enterItem交互图2:makeLineItem(desc,qty)enterItem(id,qty)1:desc=getProductDesc(id)2.1:create(desc,qty)1.1:desc=get(i