Hi,

I'm sure someone can give a much better and more in-depth explanation but
here goes:

1. Class side initialization is generally used to create fully functional
objects. If you use just instance-side you might forget to set some
important value (let's say ID) which would leave the object in invalid
state. Another reason would be that it shows what does one really need to
create a valid instance. If you have Empoyee class>>id: anId name: aName
you will now know that salary is actually not needed and the object is able
to cope with that. (And you can set it later). Yet another reason would be
setting some additional/default values (however this can be done also
internally on the instance-side).

2. Some elementary examples might be Rectangle or Point in Kernel >
BasicObjects package. Generally you wouldn't send Employee message new
directly, because that is class-side's job now, but rather you send the
actual values: Employee id: 123 name: 'John Doe'. "answers with an Employee
instance"

Peter


On Wed, Jul 23, 2014 at 8:33 AM, Dokania, Harshit <hdoka...@illinois.edu>
wrote:

> Hello,
>
> I am creating an Object Relational Mapper in pharo using sqlite.
>
> While creating database I am using a dictionary for columns of Database.
> This gives me Keys as column name and values as Data type of those.
>
> So suppose Employee is the the table name, with ID->Integer, Name->Text,
> Salary->Float.
>
> emp:= Employee new.
> Now emp is a row of table, so for each row user has to create instance of
> Employee and then feed values to it. Later on he can pass message insert
> query to emp.
>
> So I was creating this dictionary for column at the instance side
> initialization of Employee.
>
> My instructor suggested to do that in class side initialization,
>
> My Doubts are:
>
> 1. Why should we do class side initialization instead of instance side
> initialization.
>
> 2. Could you please refer me to the link which explains how to do class
> side initialization. Because when I do Employee new, I see only instance
> side initialization is being called.
>
> Thanks,
> Harshit
>
>
>

Reply via email to