Java in the Box: Implementing the BoxScript Component Language
description
Transcript of Java in the Box: Implementing the BoxScript Component Language
Java in the Box: Java in the Box: Implementing the BoxScript Implementing the BoxScript
Component LanguageComponent Language
Yi LiuYi LiuElectrical Engineering and Computer Science Electrical Engineering and Computer Science
South Dakota State UniversitySouth Dakota State University
H. Conrad CunninghamH. Conrad CunninghamComputer and Information ScienceComputer and Information Science
University of MississippiUniversity of Mississippi
22
Software Components Software Components
33
Components – A Closer LookComponents – A Closer Look
Component1
provided required
interface
inner component Component2
required provided
44
A Simple ExampleA Simple Example
Discounting
CalPrice
Discounting2
CompositionalityFlexibility
Storage Pricing
Pricing
Discounting
Storage Discounting2
55
Key Concepts Key Concepts InterfaceInterface
Interface (type)Interface (type)– Java interface gives operation signaturesJava interface gives operation signatures
Provided interfaceProvided interface– describes operations the component implements that describes operations the component implements that
other components may use other components may use Required interfaceRequired interface
– describes operations the component uses that must be describes operations the component uses that must be implemented by another componentimplemented by another component
Price.java public interface Price{ double getPrice(int client, int item, int quantity); }
66
Key Concepts Key Concepts BoxBox
A box is a component A box is a component – whose description includes provided and required whose description includes provided and required
interfaces interfaces
– has 1..n provided interfaceshas 1..n provided interfaces
– has 0..m required interfaceshas 0..m required interfaces Boxes may beBoxes may be
– abstractabstract
– concreteconcrete atomicatomic compoundcompound
Box
… P1 Pn
…
R1 Rn
1…n
0…m
77
Key Concepts Key Concepts Abstract BoxAbstract Box
Abstract boxAbstract box– does not implement provided interfaces does not implement provided interfaces – implemented by concrete boxes implemented by concrete boxes
PricingAbs.boxPricingAbs.boxabstract box PricingAbsabstract box PricingAbs{ provided interface Price Pr; { provided interface Price Pr; required interface Discount Dc,required interface Discount Dc,
PriceRetrieve PrRt;PriceRetrieve PrRt;}}
Interface typeInterface Handle
PricePr
PricingAbs
Discount
DcPriceRetrie
ve
PrRt
88
Key Concepts Key Concepts Concrete BoxConcrete Box
Atomic boxAtomic box– does not contain any other boxesdoes not contain any other boxes– implements the provided interfacesimplements the provided interfaces
Pricing.boxPricing.boxbox Pricing implements PricingAbsbox Pricing implements PricingAbs{ provided interface Price Pr; { provided interface Price Pr; required interface Discount Dc; required interface Discount Dc; }}
Interface handle
Interface type
PricePr
Pricing
Discount
DcPriceRetrie
ve
PrRt
99
Key Concepts Key Concepts Interface Implementation for Atomic BoxInterface Implementation for Atomic Box
PrImp.java PrImp.java public class PrImp implements Pricepublic class PrImp implements Price{ private BoxTop _box; { private BoxTop _box; Discount dc; // required interfaceDiscount dc; // required interface PriceRetrieve prRt; //required interfacePriceRetrieve 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; }}}}
PricePr
Pricing
Discount
DcPriceRetrie
ve
PrRt
1010
Key Concepts Key Concepts Compound BoxCompound Box
Compound boxCompound box– Composed from atomic boxes or other Composed from atomic boxes or other
compound boxescompound boxes– Follows composition rulesFollows composition rules
hide provided interfaces unless explicitly exposed hide provided interfaces unless explicitly exposed must expose required interface of constituent must expose required interface of constituent
unless connected to provided interface of another unless connected to provided interface of another constituentconstituent
1111
Key ConceptsKey Concepts Compound Box ExampleCompound Box Example
box box CalPriceCalPrice implements CalPriceAbs implements CalPriceAbs{ { composed fromcomposed from PricingAbs PricingAbs boxPboxP, DiscountingAbs , DiscountingAbs boxD, boxD, StorageAbsStorageAbs boxSboxS ; ; provided interface Price provided interface Price tPricetPrice fromfrom boxP.PrboxP.Pr; ; connectconnect boxP.DcboxP.Dc toto boxD.Dis, boxP.PrRt boxD.Dis, boxP.PrRt toto boxS.PrRt; boxS.PrRt; }} tPric
ePrice
CalPriceCalPrice
Discount Dis
DiscountingAbs boxD
box handle
PriceRetrieve PrRt
StorageAbs boxS
Pr
PricingAbs boxP
DiscountDc
Price
PriceRetrievePrRt
1212
Key ConceptsKey Concepts Box VariantBox Variant
Box variantsBox variants– Enable flexibility Enable flexibility – Implement same (parent) abstract boxImplement same (parent) abstract box– Can be substituted for each otherCan be substituted for each other– Conform to their (parent) abstract boxConform to their (parent) abstract box
provide at least the provided interfaces of parentprovide at least the provided interfaces of parent require at most the required interfaces of parentrequire at most the required interfaces of parent
1313
Key ConceptsKey Concepts Box ConformityBox Conformity
B BAbs
P1 P2 P3
IP1 IP2’ IP3
R1 R2 IR1 IR2
P1 P2
IP1 IP2
R1 R2 IR1’ IR2 IR3
R3
SupposeSuppose IP2’ extends IP2IP2’ extends IP2 IR1’ extends IR1IR1’ extends IR1
B conforms to BAbs
Provided interfaces
Required interfaces
1414
BoxScript ImplementationBoxScript ImplementationBox Source Code and CompilationBox Source Code and Compilation
For all boxesFor all boxes– interfaces (.java) interfaces (.java) by user by user – box description (.box) box description (.box) by user by user
For atomic boxes onlyFor atomic boxes only– interface implementation (.java) interface implementation (.java) by user by user
For concrete boxes only For concrete boxes only – configuration information (.conf) configuration information (.conf) by user by user – box manager code (.java) box manager code (.java) by compiler by compiler
Box code BoxCompiler Java code Java Compiler
1515
BoxScript Implementation BoxScript Implementation Box Manager ImplementationBox Manager Implementation
packagepackage declaration declaration– define filesystem usagedefine filesystem usage
importimport– interfaceinterface declarationsdeclarations
– data type declarationsdata type declarations variable declarationsvariable declarations
– instance variables for classinstance variables for class classclass definition definition
Concrete Box B
B.java
Box manager
1616
BoxScript ImplementationBoxScript Implementation Box Runtime StructureBox Runtime Structure
<<Java class >> Pricing
<<Java class >> Discounting
<<Java class >> PrImp
<<interface >> Price
<<Java class >> DisImp
<<interface >> Discount
implements
implements
instantiates
instantiates
constructor Pricing
constructor Discounting
<<Java class >> CalPrice
constructor CalPrice
instantiates Pricing
instantiates Discounting
references
references
Lazy instantiation
1717
BoxScript ImplementationBoxScript Implementation Box Manager CodeBox Manager Code
Generated by compilerGenerated by compiler– to instantiate box instancesto instantiate box instances
– to assign references to interface handlesto assign references to interface handles
1818
BoxScript Implementation BoxScript Implementation Box Manager ImplementationBox Manager Implementation
Supports lazy instantiation Supports lazy instantiation – BoxTopBoxTop
BoxTop
BoxTop()void setProvInterfacceDsc(InterfaceDsc pItfDsc)void setRequInterfaceDsc(InterfaceDsc rItfDsc)Object getProvidedItf(InterfaceName name)Object getRequiredItf(InterfaceName name)void setRequiredItf(InterfaceName iname, Object objRef)
1919
BoxScript Implementation BoxScript Implementation Box Manager ImplementationBox Manager Implementation
Code generation Code generation
generateCode (B’dscFile, mngFile) //mngFile : filename for box manager generateCode (B’dscFile, mngFile) //mngFile : filename for box manager
read in dscFile read in dscFile
genPackage();genPackage();
genImports();genImports();
genVars();genVars();
genConstructor();genConstructor();
genGetProvidedItf(); genGetProvidedItf(); // generate overriding method getProvidedItf// generate overriding method getProvidedItf
if B is compoundif B is compound genSetRequiredItf(); genSetRequiredItf(); // generate overriding method// generate overriding method setRequiredItfsetRequiredItf
writeIntoFile(mngFile);writeIntoFile(mngFile);
2020
ConclusionConclusion
Component-oriented programming Component-oriented programming language BoxScriptlanguage BoxScript– Builds upon JavaBuilds upon Java– Provides novel concepts of Provides novel concepts of
box type structure box type structure box variantsbox variants box conformitybox conformity interface satisfaction interface satisfaction
to support to support compositioncomposition and and flexibilityflexibility
2121
QuestionsQuestions