[Newbies] Adapter Pattern in SmallTalk
KingNothing
petpa0l0 at hotmail.com
Wed Aug 29 11:03:04 UTC 2007
Hi, i'm new to this forum and to smalltalk.
I've got to implement now the Adapeter Pattern in SmallTalk.
I've got an example in Java that i must translate in SmallTalk.
Here there are the Java Classes :
------------------------------------------
public class Glass
{
/**
in 12th of pint
*/
float content;
public Glass()
{
content=0;
}
/**
*/
public void fill(float filling)
{
content=filling;
}
public String toString()
{
return
super.toString()+
", level (12th of pint)="+content;
}
}
-------------------------------
public class Keg
{
/**
content, in 12th of pint units
*/
float filled;
/**
absolute level, in pints
*/
public float getLevel()
{
return filled/12;
}
float original;
/**
in pints
*/
public float getCapacity()
{
return original/12;
}
/**
Keg filled with total gallons of beer
*/
public Keg(float total)
{
filled=total*8*12;
original=filled;
}
/**
creates a Glass filled with
quantity/12 pints of beer
*/
public Glass draw(float quantity)
{
Glass g=new Glass();
g.fill(quantity);
filled-=quantity;
return g;
}
/**
% level
*/
public float getPLevel()
{
return (100*filled)/original;
}
public String toString()
{
return
super.toString()+
", level (%)="+getPLevel()+
", level (pints)="+getLevel();
}
}
---------------------------------
public class Fusto
{
/**
rapporto LITRO/PINTA
*/
public final static float LITRO_PINTA=2.1133f;
Keg keg;
public Fusto(Keg k)
{
keg=k;
}
/**
crea un Glass riempito con
quant/10 litri di birra
*/
public Glass spilla(float quant)
{
return keg.draw(quant*LITRO_PINTA*12/10);
}
/**
in litri, NON in percentuale!!!
*/
public float fornisciLivello()
{
return keg.getLevel()/LITRO_PINTA;
}
/**
in percentuale
*/
public float fornisciPLivello()
{
return keg.getPLevel();
}
public String toString()
{
return
super.toString()+
", livello (%)="+fornisciPLivello()+
", livello (litri)="+fornisciLivello();
}
}
-------------------------------------
Can someone give me some hints to translate java code into SmallTalk ?
Thanks in advance.
--
View this message in context: http://www.nabble.com/Adapter-Pattern-in-SmallTalk-tf4347089.html#a12384904
Sent from the Squeak - Beginners mailing list archive at Nabble.com.
More information about the Beginners
mailing list