One class generated by mm,

xiaoxiao2021-03-06  42

Original posted: http://community.9cbs.net/expert/topic/3793/3793756.xml Here is his MM diagram, there is MM can be introduced to see. Code Pro3.Pasunit Pro3;

Interface

Uses sysutils, dialogs, contnrs;

type TProduct = class (TObject) private FName: string; FPrice: Double; function GetName: string; function GetPrice: Double; procedure SetName (const Value: string); procedure SetPrice (Value: Double); public constructor Create; overload; procedure SayHello; virtual; property Name: string read GetName write SetName; property Price: Double read GetPrice write setPrice; end; TProductXY = class (TProduct) public procedure SayHello; overload; end; TProductZY = class (TProduct) public procedure SayHello; overload; end; TStore = class (TObject) private FProductList: TObjectList; function GetProductList: TObjectList; public constructor Create; destructor Destroy; override; procedure AddProduct (aProduct: TProduct); property ProductList: TObjectList read GetProductList; end;

IMPLEMENTATION

{******************************** TPRODUCT ************* *********************} constructor tproduct.create; begin fname: = 'product tproduct'; fPRICE: = 0; showMessage ('product is created ") ;

Function tproduct.getname: string; begin result: = FNAME; END;

Function TPRODUCT.GETPRICE: Double; Begin Result: = fprice;

Procedure tproduct.sayhello; beginnd;

Procedure tproduct.setname (const value: string); begin if fname: = value else: = value else;

Procedure tproduct.SetPrice (value: double); begin if value> 0 the fprice: = value else fPRICE: = 0;

{******************************* TPRODUCTXY ************************ ********************} procedure tproductxy.sayhello; begin showMessage ('I am Western medicine, my name is' Name 'single price:' floattostr (price) ); End; {******************************** TPRODUCTZY *********** ********************************} procedure tproductzy.sayhello; begin showmessage ('I am Chinese medicine, my name is' name 'single price:' FLOATTOSTR (Price); END;

{********************************* TSTORE ************ ***********************} constructor tstore.create; begin fproductList: = TobjectList.create (); fProductList.OwnsObjects: = true; // FProductList automatically destroyed the object end from it under destruction;

DESTRUCTOR TSTORE.DESTROY; begin fproductlist.free; inherited destroy;

Procedure tstore.addproduct (Aproduct: tproduct); begin fProductList.Add (Aproduct); showMessage (Aproduct.Name 'is added "); END;

Function TStore.getProductList: = fproductlist;

End.

转载请注明原文地址:https://www.9cbs.com/read-53432.html

New Post(0)