Re: [Newbies] A question of Squeak

2007-10-27 Thread karl

David Corking wrote:

On 10/23/07, luisalejan1308  wrote:
  

Hello If you remember I talked to you about the extension Frm, Frm is
the necessary extent to pass one imagen to squeak and only I found the
extention of PNG, so that process is wrong. I want that a robot looks like
image that I import as FRM extention, but I used the all images on PNG
extention. (Because the Squeak Book says that It needs a image in FRM
Extention to use in the program with robots). How can I convert the  formats
images???



Aha!  You mean Stephane Ducasse's book 'Squeak: Learn programming with robots'.

I found pages 69 and 70 with google books,

http://books.google.com/books?id=Zjp4t0qafZoCpg=PA70lpg=PA70dq=squeak+robots+frm+image+extensionsource=webots=EQMIWaUgqnsig=E_QDdiy6Z9vydosjNCaMN_aPn2o#PPA70,M1

So I downloaded BotsInc:

http://smallwiki.unibe.ch/botsinc/download/

Like you I am a newbie - but it seems the 'FRM' format of the turtle
and spider image is the native Squeak 'Form' class:

http://www.oldenbuettel.de/squeak-doku/Graphics-Display%20Objects/Form.html

Unfortunately, I browsed that class, and I can't find a method for
converting PNG files into FRM format.

Perhaps there is a way to make a Bot wear a PNG graphic as a costume
(you can drag them into BotsInc easily, and they become a Sketch
Morph.  The halo menu has a 'Keep as bot costume' entry  )  But, I
don't have the whole Robots book, so I can't help any further.  Sorry.

Instead, is there a paint tool in BotsInc for making new costumes?

Once a png image is filed into Squeak it is a form.
Karl
___
Beginners mailing list
Beginners@lists.squeakfoundation.org
http://lists.squeakfoundation.org/mailman/listinfo/beginners


Re: [Newbies] Concrete classes... multiple users

2007-10-27 Thread John Almberg

Hi Ron,

In a nutshell, I have an application that needs to read Items from a  
database.


I recently discovered that in Smalltalk classes are real objects.  
This struck me as cool, so when I was deciding how to instantiate  
these Items, I thought, hey I'll use the class object as a factory  
(actually, I think it's more of an adapter pattern, but...)


So I taught the Item class object how to talk to the database,  
including username/password, and then I was able to do something like:


item = Item findById: 2

And items from the database were instantiated as Items, seemingly by  
magic.


This seemed so intuitive and simple, and just 'right'. It  
encapsulated and hid the whole legacy database messiness and adapted  
the database fields into the Item attributes I really needed.


Best of all, it could later be reprogrammed to talk to a slightly  
different database and adapt that database's fields into exactly the  
same Items, so the rest of the program didn't have to know it was  
talking to a different database.


The problem arose when I needed to talk to more than one database *at  
the same time*, since the Item class was programmed to talk to a  
specific database. The only way to talk to another database was to  
update the class variables before asking for the new Item. This was  
ugly and, worse, the Item users had to know that there were different  
databases to deal with.


Anyway, yesterday I realized I needed multiple objects to connect to  
multiple databases. I figured I had two choices:

  - subclass the Item class
  - refactor entirely and build something like an ItemAdapter class,  
who's instantiated objects would connect to the database, create Item  
objects, initialize them from the data records, and hand them to the  
Item consumers.


The second choice seemed the better, so that's what I did.

So, I think it was a case of falling in love with a cool feature, and  
then mis-applying it, just because it was dying to be used.


Hope this explains it... I'm afraid I don't always get the jargon  
right, but that's why I'm a newbie, I guess!


-- John



On Oct 26, 2007, at 10:48 PM, Ron Teitelbaum wrote:


Hi John,

I read your question, but had some trouble trying to understand  
what you did

or why you are having trouble now that you have to connect to multiple
databases.

You say that you have only one Item class.  That's good because  
your domain

classes shouldn't be affected by your backend database.  You mention a
factory to decide on and build your adapter.  That's good too  
because based

on some rule you would need to figure out what database to use.

Then I get foggy, you say you have to change class variables.  Ok  
so I'm
guessing that your factory sets the class variables which hold your  
adaptors

that are used to pull items.

I think your question is: how can I keep from having to change  
database
adapter class variables?  If this is not your question please let  
me know.


The answer to that question is to modify your model to provide the
flexibility you need so that you can supply adaptors to your  
application.
Don't use class variables, use some other object instead.  Classes  
are cheap

if you need more functionality.

There is some rule that you are modeling that tells you when you  
need one
database versus another database.  You already have adapters that  
handle the
different databases, so you only need to build a new object to hold  
those
database sessions, built from your factory, and some session  
manager that

knows when to attach and which adapter to use.

So build a session manager, that holds multiple database sessions
(adapters), and code the logic for picking a session on the  
manager.  When

global behavior stops being global move from class side (and class
variables) to a new class instance and model there instead.  Let me  
know if
any of that wasn't clear, feel free to provide more specific  
information

about what you are trying to do.

Happy Coding!!

Ron Teitelbaum
President / Principal Software Engineer
US Medical Record Specialists


From: John Almberg

One of the cool things, I think, about Smalltalk is that Classes are
objects... i.e. concrete factories that can be modified at runtime to
produce objects in different ways, depending on the runtime  
situation. I
just find this so much more intuitive, compared to how classes are  
done in

other languages...

But I think I may have used it in a naive way...

For example, I needed an Adapter class that could produce standard  
Item
objects by connecting to a variety of legacy database tables,  
converting the
non-standard item records into standard Item objects. This way, the  
consumer

of those Item objects doesn't care where the items come from.

Originally, I thought I would only have to make these connections,  
one at a
time. I.e., I'd program the Item class 'factory' with the legacy  
database
hostname, username, password, and 

RE: [Newbies] Concrete classes... multiple users

2007-10-27 Thread Ron Teitelbaum
Hi John,

Good luck with your project.  By the way if you haven't already heard about
it you might want to look at Glorp.  Glorp is an object to RDBMS mapping
system for Smalltalk (written in VW but ported to Squeak).  It is possible
that it is more complicated then you need but you may find that it is very
useful.  Reading the documentation may also give you some idea of the types
of issues that you may encounter in your system.  

It does sound like you are having fun.  There is nothing like solving real
problems for learning.

Happy coding!!

Ron

 -Original Message-
 From: John Almberg
 
 Hi Ron,
 
 In a nutshell, I have an application that needs to read Items from a
 database.
 
 I recently discovered that in Smalltalk classes are real objects.
 This struck me as cool, so when I was deciding how to instantiate
 these Items, I thought, hey I'll use the class object as a factory
 (actually, I think it's more of an adapter pattern, but...)
 
 So I taught the Item class object how to talk to the database,
 including username/password, and then I was able to do something like:
 
 item = Item findById: 2
 
 And items from the database were instantiated as Items, seemingly by
 magic.
 
 This seemed so intuitive and simple, and just 'right'. It
 encapsulated and hid the whole legacy database messiness and adapted
 the database fields into the Item attributes I really needed.
 
 Best of all, it could later be reprogrammed to talk to a slightly
 different database and adapt that database's fields into exactly the
 same Items, so the rest of the program didn't have to know it was
 talking to a different database.
 
 The problem arose when I needed to talk to more than one database *at
 the same time*, since the Item class was programmed to talk to a
 specific database. The only way to talk to another database was to
 update the class variables before asking for the new Item. This was
 ugly and, worse, the Item users had to know that there were different
 databases to deal with.
 
 Anyway, yesterday I realized I needed multiple objects to connect to
 multiple databases. I figured I had two choices:
- subclass the Item class
- refactor entirely and build something like an ItemAdapter class,
 who's instantiated objects would connect to the database, create Item
 objects, initialize them from the data records, and hand them to the
 Item consumers.
 
 The second choice seemed the better, so that's what I did.
 
 So, I think it was a case of falling in love with a cool feature, and
 then mis-applying it, just because it was dying to be used.
 
 Hope this explains it... I'm afraid I don't always get the jargon
 right, but that's why I'm a newbie, I guess!
 
 -- John
 
 
 
 On Oct 26, 2007, at 10:48 PM, Ron Teitelbaum wrote:
 
  Hi John,
 
  I read your question, but had some trouble trying to understand
  what you did
  or why you are having trouble now that you have to connect to multiple
  databases.
 
  You say that you have only one Item class.  That's good because
  your domain
  classes shouldn't be affected by your backend database.  You mention a
  factory to decide on and build your adapter.  That's good too
  because based
  on some rule you would need to figure out what database to use.
 
  Then I get foggy, you say you have to change class variables.  Ok
  so I'm
  guessing that your factory sets the class variables which hold your
  adaptors
  that are used to pull items.
 
  I think your question is: how can I keep from having to change
  database
  adapter class variables?  If this is not your question please let
  me know.
 
  The answer to that question is to modify your model to provide the
  flexibility you need so that you can supply adaptors to your
  application.
  Don't use class variables, use some other object instead.  Classes
  are cheap
  if you need more functionality.
 
  There is some rule that you are modeling that tells you when you
  need one
  database versus another database.  You already have adapters that
  handle the
  different databases, so you only need to build a new object to hold
  those
  database sessions, built from your factory, and some session
  manager that
  knows when to attach and which adapter to use.
 
  So build a session manager, that holds multiple database sessions
  (adapters), and code the logic for picking a session on the
  manager.  When
  global behavior stops being global move from class side (and class
  variables) to a new class instance and model there instead.  Let me
  know if
  any of that wasn't clear, feel free to provide more specific
  information
  about what you are trying to do.
 
  Happy Coding!!
 
  Ron Teitelbaum
  President / Principal Software Engineer
  US Medical Record Specialists
 
  
  From: John Almberg
 
  One of the cool things, I think, about Smalltalk is that Classes are
  objects... i.e. concrete factories that can be modified at runtime to
  produce objects in