Presentation is loading. Please wait.

Presentation is loading. Please wait.

Java in the Box: Implementing the BoxScript Component Language Yi Liu Electrical Engineering and Computer Science South Dakota State University H. Conrad.

Similar presentations


Presentation on theme: "Java in the Box: Implementing the BoxScript Component Language Yi Liu Electrical Engineering and Computer Science South Dakota State University H. Conrad."— Presentation transcript:

1 Java in the Box: Implementing the BoxScript Component Language Yi Liu Electrical Engineering and Computer Science South Dakota State University H. Conrad Cunningham Computer and Information Science University of Mississippi

2 2 Software Components

3 3 Components – A Closer Look Component1 provided required interface inner component Component2 required provided

4 4 A Simple Example Discounting CalPrice Discounting2 Compositionality Flexibility StoragePricing Discounting Storage Discounting2

5 5 Key Concepts Interface Interface (type) Interface (type) –Java interface gives operation signatures Provided interface Provided interface –describes operations the component implements that other components may use Required interface Required interface –describes operations the component uses that must be implemented by another component Price.java public interface Price { double getPrice(int client, int item, int quantity); }

6 6 Key Concepts Box A box is a component A box is a component –whose description includes provided and required interfaces –has 1..n provided interfaces –has 0..m required interfaces Boxes may be Boxes may be –abstract –concrete atomic atomic compound compound Box … P 1 Pn … R 1 Rn 1…n 0…m

7 7 Key Concepts Abstract Box Abstract box Abstract box –does not implement provided interfaces –implemented by concrete boxes PricingAbs.box abstract box PricingAbs { provided interface Price Pr; required interface Discount Dc, required interface Discount Dc, PriceRetrieve PrRt; PriceRetrieve PrRt;} Interface type Interface Handle Price Pr PricingAbs Discount Dc PriceRetrieve PrRt

8 8 Key Concepts Concrete Box Atomic box Atomic box –does not contain any other boxes –implements the provided interfaces Pricing.box box Pricing implements PricingAbs { provided interface Price Pr; required interface Discount Dc; required interface Discount Dc;} Interface handle Interface type Price Pr Pricing Discount Dc PriceRetrieve PrRt

9 9 Key Concepts Interface Implementation for Atomic Box PrImp.java public class PrImp implements Price { private BoxTop _box; Discount dc; // required interface Discount dc; // required interface PriceRetrieve prRt; //required interface PriceRetrieve prRt; //required interface public PrImp(BoxTop myBox) public PrImp(BoxTop myBox) { _box = myBox; { _box = myBox; InterfaceName name = new InterfaceName("Dc"); InterfaceName name = new InterfaceName("Dc"); dc = (Discount)_box.getRequiredItf(name); dc = (Discount)_box.getRequiredItf(name); name = new InterfaceName(“PrRt"); name = new InterfaceName(“PrRt"); prRt = (PriceRetrieve)_box.getRequiredItf(name); prRt = (PriceRetrieve)_box.getRequiredItf(name); } public double getPrice(int client,int item,int quantity) public double getPrice(int client,int item,int quantity) { double price = prRt.itemPrice(item); { double price = prRt.itemPrice(item); double disc = dc.getDiscount(client, item, quantity); double disc = dc.getDiscount(client, item, quantity); return price * (1 – disc * 0.01) * quantity; return price * (1 – disc * 0.01) * quantity; }} Price Pr Pricing Discount Dc PriceRetrieve PrRt

10 10 Key Concepts Compound Box Compound box Compound box –Composed from atomic boxes or other compound boxes –Follows composition rules hide provided interfaces unless explicitly exposed hide provided interfaces unless explicitly exposed must expose required interface of constituent unless connected to provided interface of another constituent must expose required interface of constituent unless connected to provided interface of another constituent

11 11 Key Concepts Compound Box Example box CalPrice implements CalPriceAbs { composed from PricingAbs boxP, DiscountingAbs boxD, StorageAbs boxS ; provided interface Price tPrice from boxP.Pr; provided interface Price tPrice from boxP.Pr; connect boxP.Dc to boxD.Dis, boxP.PrRt to boxS.PrRt; connect boxP.Dc to boxD.Dis, boxP.PrRt to boxS.PrRt;} tPrice Price CalPrice Discount Dis DiscountingAbs boxD box handle PriceRetrieve PrRt StorageAbs boxS Pr PricingAbs boxP Discount Dc Price PriceRetrieve PrRt

12 12 Key Concepts Box Variant Box variants Box variants –Enable flexibility –Implement same (parent) abstract box –Can be substituted for each other –Conform to their (parent) abstract box provide at least the provided interfaces of parent provide at least the provided interfaces of parent require at most the required interfaces of parent require at most the required interfaces of parent

13 13 Key Concepts Box Conformity B BAbs P1 P2 P3 IP1 IP2’ IP3 R1R2 IR1 IR2 P1 P2 IP1 IP2 R1R2 IR1’ IR2 IR3 R3 Suppose IP2’ extends IP2 IP2’ extends IP2 IR1’ extends IR1 IR1’ extends IR1 B conforms to BAbs Provided interfaces Required interfaces

14 14 BoxScript Implementation Box Source Code and Compilation For all boxes For all boxes –interfaces (.java) by user –box description (.box) by user For atomic boxes only For atomic boxes only –interface implementation (.java) by user For concrete boxes only For concrete boxes only –configuration information (.conf) by user –box manager code (.java) by compiler Box code BoxCompiler Java code Java Compiler

15 15 BoxScript Implementation Box Manager Implementation package declaration package declaration –define filesystem usage import import –interface declarations –data type declarations variable declarations variable declarations –instance variables for class class definition class definition Concrete Box B B.java Box manager

16 16 BoxScript Implementation Box Runtime Structure > Pricing > Discounting > PrImp > Price > DisImp > Discount implements instantiates constructor Pricing constructor Discounting > CalPrice constructor CalPrice instantiates Pricing instantiates Discounting references Lazy instantiation

17 17 BoxScript Implementation Box Manager Code Generated by compiler Generated by compiler –to instantiate box instances –to assign references to interface handles

18 18 BoxScript Implementation Box Manager Implementation Supports lazy instantiation Supports lazy instantiation –BoxTop BoxTop BoxTop() void setProvInterfacceDsc(InterfaceDsc pItfDsc) void setRequInterfaceDsc(InterfaceDsc rItfDsc) Object getProvidedItf(InterfaceName name) Object getRequiredItf(InterfaceName name) void setRequiredItf(InterfaceName iname, Object objRef)

19 19 BoxScript Implementation Box Manager Implementation Code generation Code generation generateCode (B’dscFile, mngFile) //mngFile : filename for box manager read in dscFile read in dscFile genPackage(); genPackage(); genImports(); genImports(); genVars(); genVars(); genConstructor(); genConstructor(); genGetProvidedItf(); // generate overriding method getProvidedItf genGetProvidedItf(); // generate overriding method getProvidedItf if B is compound if B is compound genSetRequiredItf(); // generate overriding method genSetRequiredItf(); // generate overriding method setRequiredItf setRequiredItf writeIntoFile(mngFile); writeIntoFile(mngFile);

20 20 Conclusion Component-oriented programming language BoxScript Component-oriented programming language BoxScript –Builds upon Java –Provides novel concepts of box type structure box type structure box variants box variants box conformity box conformity interface satisfaction interface satisfaction to support composition and flexibility

21 21 Questions


Download ppt "Java in the Box: Implementing the BoxScript Component Language Yi Liu Electrical Engineering and Computer Science South Dakota State University H. Conrad."

Similar presentations


Ads by Google