All pastes #189764 Raw Edit

Something

public text v1 · immutable
·published 2006-10-03 12:40 UTC
rendered paste body
 a class is the instructions to build an object. The object is in memory and used at runtime. When you create an object, the class is used to build it.

a class is a type of objects, an object is an actual instantiation of that type

just in case it's not clear a class is just something that describes an object. The compiler will use it to make an object. It's just a description.

so an object is like  DNA  and  a class is like  the ribosomes that construct the proteins from aminoacids  wich are blueprints  from our genes ?

More like an object is like a bike and a class is like the blueprints for that bike.

 struct integer { int value; }; integer x = 0;  
the class "integer" describes what all instances of it look like, namely they have a value.
"x" is an instance of integer with a specific value of 0.

 you can create infinite number of instances of "integer" and all of them follow the same description but can have independent values.


h class einaikati afhrhmeno poy perigrafei PWS symperiferontai ta objects poy anhkoyn SE AYTHN
_www_ ara eksorismoy exoyme MIA CLASS kai ayth perigrafei TA OBJECTS
_www_ as poyme pws exoyme thn class anthrwpos
_www_ ayth perigrafei pws leitoyrgei enas organismos as poyme
_www_ PERIGRAFEI loipon pws yparxei mia metablhth poy legetai ypsos
_www_ mia allh poy legetai baros
_www_ pws OTAN parei ena object ths a spoyme toses thermides thn hmera katanalwnei toses klp
_www_ TA OBJECTS twra poy anhkoyn se ayth thn class EXOYN ayta ta xarakthristika
_www_ ayto san prwth proseggish, katanohto?

Agiofws More like an object is like a bike and a class is like the blueprints for that bike 
_www_ ti akribws den katalabes?
_www_ poly swsta
_www_ to object einai ena SYGKRIMENO podhlato
Agiofws ara to object einai ENA 
_www_ --> to object einai ena SYGKRIMENO podhlato <---
_www_ ara exoyme POLLA objects (osa kai podhlata ston kosmo)
Agiofws kai TA classes pou perigrafoun to podilato xromoa  ipsos mikso einai pola 
_www_ oxi paidaki moy, diabase ligo prosektika ayat poy eipa
Agiofws :)
_www_ :)
_www_ na sto deiksw as poyme sxetiak me top podhlato poy eipes, ok?
Agiofws kk 
Agiofws otan kanis ena blue print diniourgeite automata kialo object ?
_www_ katarxhn ksekiname apo to bluprint, dhladh apo THN PERIGRAFH THS CLASS
_www_ oxi, akoyse me prosektika, tha anafwrthw se ola
_www_ --> katarxhn ksekiname apo to bluprint, dhladh apo THN PERIGRAFH THS CLASS
_www_ class bike {
_www_    int color;
_www_    int inmovement;
_www_    bike::bike(int col)
_www_    {
_www_       color = col;
_www_       inmovement = false;
Agiofws to object den prpei na exei dimiourgithei  prin apo to class ?
_www_    }
_www_ OXI
Agiofws ok 
_www_ tah me afhseis na teleiwsw ?
_www_ :))
Agiofws nai nai se akouw 
_www_ to object dhmioyrgeitai BASIZOMENO se mai YPARXOYSA class
_www_ as meinoyme mexri edw
_www_ ayth einaih class bike
_www_ exei mesa ths 2 eswterikes metablhthes gai na kratane to xrwma toy podhlaoty kai to an kineitai 'h oxi, ok?
Agiofws kk
_www_ h function bike::bike poy blepeis einai o constructr, dhladh h function poy tah klhthei OTAN KATASKEYASTEI ena object poy anhkei se ayth thn class
_www_ opote sto main mas prog tah exyme as poyme gia an dhmioyrghsoyme 2 PODHLATA (2 objects) tis ejhs entoles:
_www_ bike bike_of_giannhs(blue);
_www_ bike bike_of_iwanna(red);
_www_ ara exoyme DYO objects poy ftiaxthkan me bash toy TI PERIGFAREI h class bike pws einai ena podhlato
Agiofws auta einai sto global meros tou src code ?  
_www_ to ena einai kokkino kai to allo blue
_www_ yeap
_www_ sto main a spoyme
_www_ sto main as spoyme
_www_ einai ston ektelesimo kwdika
_www_ enw h class einai sto tmhma twn dhlwsewn
_www_ san ennoies ta katalabes? ayto exei shmasia arxika
_www_ tis leptomereies tha tis deis analoga me to se poia glwssa anaferesai klp klp
Agiofws nai psilokatalaba 
_www_ oi ennoeis omws einai PANTOY idies
_www_ okk
Agiofws alla 
Agiofws me berdepse pws boris na exeis blueprint prin akoma kataskeuaseis  to object 
_www_ blueprint metafrase yto sta ellhnika san ODHGIES 
Agiofws bah  pio poli san photocopy einai 
_www_ dhladh OTAN einai na kataskeyastei ena object oi odhgies aytes mas lene pws na to ftiajoyme
_www_ kai epishs mas lene pws tah symperiferetai apo kei kai meta
_www_ opws se boleyai na to thymasai :)