logo       

Re: Adapter Pattern in SmallTalk: msg#00177

lang.smalltalk.squeak.beginners

Subject: Re: Adapter Pattern in SmallTalk

Hi, if you're only interested in converting the Java code to Smalltalk, I would simple take one class at a time.  For example, using the Glass class:

Object subclass: #Glass
     instanceVariableNames: ''
     classVariableNames: ''
     poolDictionaries: ''
     category:  'Adapter-Example'

 
instance methods ' initialize-release'

initialize
   content := 0.0

instance methods 'accessing ' protocol

content:  anObject
   content := anObject

class methods 'class initialization' protocol

new
  ^super new initialize

Good luck,

-Conrad

 
On 8/29/07, KingNothing <petpa0l0@xxxxxxxxxxx> wrote:

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.

______________________________ _________________
Beginners mailing list
Beginners@xxxxxxxxxxxxxxxxxxxxon.org
http://lists.squeakfoundation .org/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
Beginners@xxxxxxxxxxxxxxxxxxxxxxxxxx
http://lists.squeakfoundation.org/mailman/listinfo/beginners
<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise