Differenze tra le versioni di "CREATE PRIVATE...CREATE STATIC"

Da Gambas-it.org - Wikipedia.
m
Riga 1: Riga 1:
'''CREATE PRIVATE, CREATE STATIC'''
+
'''CREATE PRIVATE CREATE STATIC'''
  
 
----
 
----
  
[Traduzione dalla pagina ufficiale di Gambas]
+
[Translation from the official page of Gambas]
''Queste due parole chiave, inserite all'inizio del codice di una classe, indicano all'interprete Gambas che la classe non può essere istanziata.''
+
''These two keywords, enter the code at the beginning of a class, indicate that the Gambas interpreter class can not be instantiated.''
''Questa modalità viene usata per la costruzione di classi, padri di altre classi.''
+
''This mode is used for the construction of classes, the fathers of other classes.''
  
Come già menzionato nella pagina [[Gli Oggetti e le Classi]], una classe può essere derivata da un'altra classe superiore, ereditandone le caratteristiche pubbliche e le funzionalità. Lo scopo di questa logica fà parte del concetto di oggetto (o classe), comune a tutti i linguaggi orientati agli oggetti.
+
As already mentioned in the [[Objects and Classes]], a class can be derived from another top class, inheriting the public features and functionality. The purpose of this logic is part of the concept of object (or class), common to all object-oriented languages.
  
Come anche in altri articoli, non voglio qui avviare una discussione sul concetto di classe, ma in qualche modo cercherò di spiegare il funzionamento di alcune caratterische di Gambas, collegando questo ad alcuni riferimenti e concetti generali.
+
As in other articles, I do not want to start a discussion here on the concept of class, but somehow I'll try to explain the workings of some Features of Gambas, linking this to some references and general concepts.
  
Una classe, o oggetto, può essere considerato in modo modo semplice, come una collezione di caratteristiche che ne contraddistinguono l'uso all'interno di un programma. Come per un variabile, una volta creata e istanziata a livello procedura, assume un contenuto e una forma in memoria reali, altrettanto viene fatto per una classe.
+
A class or object, can be considered in <span class="plainlinks"> [http://thebeginnerslens.com/iphone-camera-tips-and-iphone-photography <span style = "color: black; font- weight: normal; text-decoration: none! important; background: none! important; text-decoration: none; "> how to use iphone camera </ span>] simply as a collection of features that characterize the use within a program. As a variable, once created and instantiated in the procedure, a content and assumes a shape in real memory, just as is done for a class.
Una classe può contenere vari tipi di elemento, da semplici <span class="plainlinks">[http://www.diamondlinks.net/ <span style="color:black;font-weight:normal; text-decoration:none!important; background:none!important; text-decoration:none;">link building</span>] variabili a funzioni complesse; ogni volta che l'oggetto viene creato, in realtà vengono creati in memoria tutti i suoi elementi (private e pubblici). Al programma, poi, verrà ritornato il puntamento (o riferimento) in memoria del nuovo oggetto.
+
A class can contain different element types, from simple <span class="plainlinks"> [http://www.diamondlinks.net/ <span style = "color: black; font-weight: normal; text-decoration: none ! important; background: none! important; text-decoration: none; "> Link Building </ span>] complex variable functions, each time the object is created, are actually created in memory all of its elements (private and public). The program then will be returned to the point (or reference) of the new object in memory.
L'utilizzo di una variabile, o una funzione, che fà parte dell'oggetto, può essere fatta tramite il puntamento al nome stesso della variabile/funzione, passando prima per il puntamento iniziale della classe:
+
The use of a variable, or function, which is part of the object, it can be done by pointing to the name of the variable / function, passing first to the starting point of the class:
  
 
----
 
----
  
  '''DIM NuovaClasse AS Window'''       ''dichiarazione di una classe di tipo Window''
+
  '''DIM AS NuovaClasse Window'''''declaration of a class of type Window''
  ...
+
  ...
  '''NuovaClasse = NEW Window()'''     ''creazione della classe in memoria''
+
  '''''()''' NuovaClasse = NEW Window creation of the class in memory''
  ...
+
  ...
  '''NuovaClasse.Resize(x,y)'''         ''utilizzo di un metodo (o funzione) della nuova classe''
+
  '''NuovaClasse.Resize (x, y)'''''using a method (or function) of the new class''
  ...
+
  ...
  '''NuovaClasse.Caption = "Titolo"''' ''utilizzo di una proprietà della nuova classe''
+
  '''NuovaClasse.Caption = "Title"'''''using a new class of property''
  ...
+
  ...
  '''DIM NuovoPuntatore AS Window'''
+
  '''DIM AS NuovoPuntatore Window'''
  '''NuovoPuntatore = NuovaClasse'''   ''creazione di un nuovo puntatore a una classe esistente''
+
  '''NuovoPuntatore NuovaClasse ='''''creating a new pointer to an existing class''
  
 
----
 
----
  
La logica degli oggetti permette di definire una serie di caratteristiche distinte legate all'oggetto stesso.
+
The logic of the objects used to define a set of distinct characteristics related to the object itself.
  
Se associamo questa logica al mondo reale, possiamo fare un semplice esempio: immaginiamo di descrivere una matita (o lapis), utilizzando una classe chiamata ''Matita'':
+
If we associate this logic to the real world, we can take a simple example: imagine we describe a pencil (or pencil), using a class called''pencil''
  
 
----
 
----
  
  ' ''Gambas class file''
+
  'Gambas class file''''
  '
+
  '
  ' ''CLASS Matita''
+
  '''''Pencil CLASS
  .
+
  .
  '''INHERITS Object'''                     ''derivazione dalla classe padre''
+
  '''Object INHERITS'''''''derived from the parent class
  .
+
  .
  '''PUBLIC LunghezzaMatita AS Integer''''proprietà caratteristica dell'oggetto''
+
  '''LunghezzaMatita PUBLIC AS Integer'''''''characteristic property of the object
  
 
----
 
----
'''Nota:''' E' da tener presente che in Gambas, tutti gli oggetti (o classi) derivano dalla classe base Object, mentre per gli oggetti di tipo grafico esiste la sotto classe specializzata Control (che deriva anch'essa da Object).
+
'''Note:''' It must be remembered that in Gambas, all objects (or classes) are derived from the base class Object, and for graphical objects there is a specialized class in Control (which also comes from Object).
  
Ritornando all'esempio, abbiamo definito una classe ''Matita'', derivata dalla classe base '''Object'''. Da quest'ultima ne riceve tutte le caratteristiche, tra qui quelle fondamentali di creazione e distruzione dell'oggetto stesso.
+
Returning to our example, we have a class called''pencil'', derived from the base class'''object'''. From this it receives all the features, including the basic ones here of creation and destruction of the object itself.
Alla classe ''Matita'' abbiamo aggiunto, rispetto a Object, la proprietà ''LunghezzaMatita'', che nel nostro semplice esempio definisce la particolarità del nuovo oggetto; in questo caso LunghezzaMatita ha lo scopo di definire, appunto, la dimensione della matita.
+
The class''Pencil''we added, compared to Object, property LunghezzaMatita'''', which in our simple example defines the uniqueness of the new object, in this case LunghezzaMatita aims to define, precisely, the size of a pencil .
In questo modo non abbiamo fatto altro che definire un oggetto specializzato, ma ancora non ha tutti i requisiti.
+
In this way we have done is define a specialized, but still has all the requirements.
Noi sappiamo che in realtà esistono matite di ogni genere e colore, per cui occorre definire una nuova definizione dell'oggetto ''Matita'', in modo che corrisponda ad un oggetto reale. Supponiamo di voler creare una ''Matita'' che può assumere diversi colori:
+
We know that in realityThere are a pencil of every kind and color, so we need to define a new definition of''pencil'', to correspond to a real object. Suppose you want to create a''pencil''that can take on different colors:
 
----
 
----
  
  ' ''Gambas class file''
+
  'Gambas class file''''
  '
+
  '
  ' ''CLASS MatitaColorata''
+
  '''''MatitaColorata CLASS
  .
+
  .
  '''INHERITS Matita'''                   ''derivazione dalla classe padre Matita''
+
  '''INHERITS Pencil'''''Pencil''derived from the parent class
  .
+
  .
  '''PUBLIC Colore AS Color'''             ''caratteristica del nuovo oggetto''
+
  '''AS PUBLIC Color Color'''''''feature of the new object
  
 
----
 
----
In questo esempio abbiamo creato un nuovo oggetto ''MatitaColorata'', derivandola dalla classe superiore ''Matita''. Questa nuova classe eredita la proprietà pubblica ''LunghezzaMatita'' della classe superiore, ma aggiunge un'ulteriore proprietà: ''Colore''.
+
In this example we have created a new object''MatitaColorata'',''Pencil by deriving from the upper class.'' This new class inherits the''public property''LunghezzaMatita of the upper class, but adds an additional property:''Color''.
La bellezza di questa logica è che non dobbiamo scrivere nuovamente il codice per creare la matita, perchè il codice è già incluso nella classe superiore, e la classe figlia lo eredita in modo automatico.
+
The beauty of this logic is that we must not re-write the code to create a pencil, because the code is already included in the upper class, and the child class automatically inherits it.
La nuova classe è diventata una classe specializzata della classe ''Matita''.
+
The new class has become a specialized class of the class''Pencil''.
  
Uno degli scopi fondamentali della logica a oggetti, è proprio quella di non dover scrivere più volte lo stesso codice, e un oggetto può essere riutilizzato più volte per situazioni diverse.
+
One of the fundamental purposes of logical object, is precisely that of not having to repeatedly write the same code, and an object can be reused several times for different situations.
In questo modo possiamo creare oggetti diversi, derivati da una stessa fonte, ma che hanno specializzazioni diverse.
+
In this way we can create different objects, derived from the same source, but have different specializations.
Diversamente da vecchie versioni di Gambas, in queste ultime release non sembra ci siano limiti nll'inerenza di classi e sottoclassi (in alcuni miei programmi ho usato fino a 20 sottoclassi...).
+
Unlike older versions of Gambas, in these latest releases there seems no limit nll'inerenza of classes and subclasses (in some of my programs I have used up to 20 subclasses ...).
  
Ritornando alle parole chiave '''CREATE PRIVATE''' e '''CREATE STATIC'''; ammettiamo per un momento che la classe base ''Matita'' non può essere direttamente utilizzata, perchè non equipaggiata delle necessarie caratteristiche di funzionalità di una vera matita (non sappiamo neppure se ha la punta...).
+
Returning to the keywords'''CREATE PRIVATE''' and'''CREATE STATIC'''; admit for a moment that the base class''Pencil''can not be directly used, because it is not equipped with the necessary functional characteristics of a real pencil (do not even know if the point ...).
 
----
 
----
  
  
'''CREATE PRIVATE'''
+
'''''CREATE PRIVATE'
  
Dato che la classe base Matita non può essere utilizzata direttamente, diciamo a Gambas di bloccarla, e di renderla utile solo per la creazione di classi inferiori:
+
Since the base class can not be used directly Pencil, Gambas say to block it, and make it useful only for the creation of the lower classes:
 
----
 
----
  
  ' ''Gambas class file''
+
  'Gambas class file''''
  '
+
  '
  ' ''CLASS Matita''
+
  '''''Pencil CLASS
  .
+
  .
  '''INHERITS Object'''                       ''derivazione dalla classe padre Object''
+
  '''Object INHERITS'''''''derived from the parent class Object
  .
+
  .
  '''CREATE PRIVATE'''                       ''definizione di classe non istanziabile''
+
  '''CREATE PRIVATE'''''definition of a class instance''
  .
+
  .
  '''PUBLIC LunghezzaMatita AS Integer'''     ''caratteristica del nuovo oggetto''
+
  '''LunghezzaMatita PUBLIC AS Integer'''''''feature of the new object
  
 
----
 
----
La frase '''CREATE PRIVATE''' informa l'interprete di Gambas, che la classe ''Matita'' non può essere nè creata, nè istanziata all'interno del programma.
+
The phrase'''CREATE PRIVATE''' informs the Gambas interpreter,''pencil''that the class can neither be created nor instantiated within the program.
A questo punto, se vogliamo creare una vera matita, occorre creare un'altro oggetto, che assume proprietà reali (es. il colore):
+
At this point, if we want to create a real pencil, you create another object, that takes real properties (eg color):
 
----
 
----
  
  ' ''Gambas class file''
+
  'Gambas class file''''
  '
+
  '
  ' ''CLASS MatitaRossa''
+
  '''''MatitaRossa CLASS
  .
+
  .
  '''INHERITS Matita'''                       ''derivazione dalla classe padre Matita''
+
  '''INHERITS Pencil'''''Pencil''derived from the parent class
  .
+
  .
  '''PUBLIC READ Colore AS Color'''           ''proprietà caratteristica del nuovo oggetto''
+
  '''PUBLIC READ AS Color Color'''''characteristic property of the new object''
  .
+
  .
  '''PUBLIC FUNCTION Colore_Read()'''         ''metodo per il ritorno del valore della proprietà di colore''
+
  '''Public Function Colore_Read ()'''''method to return the property value of color''
    '''RETURN Color.Red'''                   ''valore ritornato''
+
    '''RETURN Color.Red'''''''return value
  '''END'''
+
  '''''END'
  
 
----
 
----
La nuova classe MatitaRossa non altro che la classe base Matita, ma con una caratteristica particolare: è rossa.
+
The new class MatitaRossa no more than the base class pencil, but with a special feature: it is red.
La nuova proprierà Colore (che è impostata in sola lettura), ritorna il valore costante Red, della classe base statica Color di Gambas.
+
The new proprierà color (which is set to read-only), Red returns the constant value, the base class static Color Gambas.
 
----
 
----
  
Riga 114: Riga 114:
 
'''CREATE STATIC'''
 
'''CREATE STATIC'''
  
La frase chiave '''CREATE STATIC''', a differenza della precedente, dice all'inteprete di Gambas che la classe in oggetto, oltre a non poter essere creata, e quindi istanziata, deve essere creata in memoria in modo automatico, e che deve essere accessibile già in fase di avvio programma.
+
The phrase'''CREATE STATIC''', unlike its predecessor, says all'inteprete Gambas that the class in question, besides not being able to be created, and then instantiated, must be created in memory automatically, and that should be accessible already at boot program.
Questo vuol dire che, a differenza di una normale classe o di una classe privata (vedi precedente), la nuova classe è già disponibile e attiva, senza bisogno di istruzioni di creazione. Esempi, in Gambas, sono le classi Form e Settings, che sono direttamente utilizzabili, in pratica sono create automaticamente e al volo...
+
This means that, unlike a normal class or private class (see above), the new class is already available and active, without any instructions to create. Examples in gambas, Forms are the classes and Settings, which are directly used in practice are automatically created on the fly ...
Come per '''CREATE PRIVATE''', la sintassi deve trovarsi all'inizio del codice della classe, o subito dopo un'istruzione [[INHERITS]].
+
As with'''CREATE PRIVATE''', the syntax must be at the beginning of the class code, or immediately after an instruction [[INHERITS]].
 
----
 
----
  
  ' ''Gambas class file''
+
  'Gambas class file''''
  '
+
  '
  ' ''CLASS Matita''
+
  '''''Pencil CLASS
  .
+
  .
  '''CREATE STATIC'''                   ''definizione di classe statica''
+
  '''CREATE STATIC'''''definition of''static class
  
 
----
 
----
  
  ' ''Gambas class file''
+
  'Gambas class file''''
  '
+
  '
  ' ''CLASS MatitaRossa''
+
  '''''MatitaRossa CLASS
  .
+
  .
  INHERITS Matita
+
  INHERITS Pencil
  .
+
  .
  '''CREATE STATIC'''                   ''definizione di sotto classe statica''
+
  '''CREATE STATIC''' definition''under''static class
  
 
----
 
----
A differenza dell'esempio fatto per '''CREATE PRIVATE''', la nuova classe ''MatitaRossa'' assume sì le proprietà della classe superiore ''Matita'', ma non c'è bisono di crearla, perchè lo fa in automatico l'interprete di Gambas all'avio del programma, e la classe è immediatamente disponibile per l'uso.
+
Unlike the made for'''CREATE PRIVATE''', the new class MatitaRossa''yes''takes on the properties of the upper class''Pencil'', but there is Bisonó to create it, because he does automatically the Gambas interpreter to having the program, and the class is immediately available for use.
  
E' ovvio che, in questo caso, non è possibile avere a disposizione, e quindi creare, multiple istanze dello stesso oggetto, per cui questo tipo di approccio ha l'obiettivo basilare di: mantenere una gestione del programma a oggetti, e l'utilizzo di una classe statica come una sorta di contenitore di funzionalità specifiche, un pò come poi è il modulo in Gambas.
+
It 'obvious that, in this case, it is not possible to have, and then create multiple instances of the same object, so this approach has the basic purpose of: maintaining an object-oriented program management, and' Using a static class as a kind of container-specific features, then it is a bit like the form in Gambas.

Versione delle 23:43, 3 ago 2011

CREATE PRIVATE CREATE STATIC


[Translation from the official page of Gambas] These two keywords, enter the code at the beginning of a class, indicate that the Gambas interpreter class can not be instantiated. This mode is used for the construction of classes, the fathers of other classes.

As already mentioned in the Objects and Classes, a class can be derived from another top class, inheriting the public features and functionality. The purpose of this logic is part of the concept of object (or class), common to all object-oriented languages.

As in other articles, I do not want to start a discussion here on the concept of class, but somehow I'll try to explain the workings of some Features of Gambas, linking this to some references and general concepts.

A class or object, can be considered in how to use iphone camera </ span> simply as a collection of features that characterize the use within a program. As a variable, once created and instantiated in the procedure, a content and assumes a shape in real memory, just as is done for a class. A class can contain different element types, from simple Link Building </ span> complex variable functions, each time the object is created, are actually created in memory all of its elements (private and public). The program then will be returned to the point (or reference) of the new object in memory. The use of a variable, or function, which is part of the object, it can be done by pointing to the name of the variable / function, passing first to the starting point of the class:


  DIM AS NuovaClasse Windowdeclaration of a class of type Window   ...   () NuovaClasse = NEW Window creation of the class in memory   ...   NuovaClasse.Resize (x, y)using a method (or function) of the new class   ...   NuovaClasse.Caption = "Title"using a new class of property   ...   DIM AS NuovoPuntatore Window   NuovoPuntatore NuovaClasse =creating a new pointer to an existing class


The logic of the objects used to define a set of distinct characteristics related to the object itself.

If we associate this logic to the real world, we can take a simple example: imagine we describe a pencil (or pencil), using a class calledpencil


  'Gambas class file'   '   Pencil CLASS   .   Object INHERITS''derived from the parent class   .   LunghezzaMatita PUBLIC AS Integer''characteristic property of the object


Note: It must be remembered that in Gambas, all objects (or classes) are derived from the base class Object, and for graphical objects there is a specialized class in Control (which also comes from Object).

Returning to our example, we have a class calledpencil, derived from the base classobject. From this it receives all the features, including the basic ones here of creation and destruction of the object itself. The classPencilwe added, compared to Object, property LunghezzaMatita', which in our simple example defines the uniqueness of the new object, in this case LunghezzaMatita aims to define, precisely, the size of a pencil . In this way we have done is define a specialized, but still has all the requirements. We know that in realityThere are a pencil of every kind and color, so we need to define a new definition ofpencil, to correspond to a real object. Suppose you want to create apencilthat can take on different colors:


  'Gambas class file'   '   MatitaColorata CLASS   .   INHERITS PencilPencilderived from the parent class   .   AS PUBLIC Color Color''feature of the new object


In this example we have created a new objectMatitaColorata,Pencil by deriving from the upper class. This new class inherits thepublic propertyLunghezzaMatita of the upper class, but adds an additional property:Color. The beauty of this logic is that we must not re-write the code to create a pencil, because the code is already included in the upper class, and the child class automatically inherits it. The new class has become a specialized class of the classPencil.

One of the fundamental purposes of logical object, is precisely that of not having to repeatedly write the same code, and an object can be reused several times for different situations. In this way we can create different objects, derived from the same source, but have different specializations. Unlike older versions of Gambas, in these latest releases there seems no limit nll'inerenza of classes and subclasses (in some of my programs I have used up to 20 subclasses ...).

Returning to the keywordsCREATE PRIVATE andCREATE STATIC; admit for a moment that the base classPencilcan not be directly used, because it is not equipped with the necessary functional characteristics of a real pencil (do not even know if the point ...).



CREATE PRIVATE'

Since the base class can not be used directly Pencil, Gambas say to block it, and make it useful only for the creation of the lower classes:


  'Gambas class file'   '   Pencil CLASS   .   Object INHERITS''derived from the parent class Object   .   CREATE PRIVATEdefinition of a class instance   .   LunghezzaMatita PUBLIC AS Integer''feature of the new object


The phraseCREATE PRIVATE informs the Gambas interpreter,pencilthat the class can neither be created nor instantiated within the program. At this point, if we want to create a real pencil, you create another object, that takes real properties (eg color):


  'Gambas class file'   '   MatitaRossa CLASS   .   INHERITS PencilPencilderived from the parent class   .   PUBLIC READ AS Color Colorcharacteristic property of the new object   .   Public Function Colore_Read ()method to return the property value of color     RETURN Color.Red''return value   END'


The new class MatitaRossa no more than the base class pencil, but with a special feature: it is red. The new proprierà color (which is set to read-only), Red returns the constant value, the base class static Color Gambas.



CREATE STATIC

The phraseCREATE STATIC, unlike its predecessor, says all'inteprete Gambas that the class in question, besides not being able to be created, and then instantiated, must be created in memory automatically, and that should be accessible already at boot program. This means that, unlike a normal class or private class (see above), the new class is already available and active, without any instructions to create. Examples in gambas, Forms are the classes and Settings, which are directly used in practice are automatically created on the fly ... As withCREATE PRIVATE, the syntax must be at the beginning of the class code, or immediately after an instruction INHERITS.


  'Gambas class file'   '   Pencil CLASS   .   CREATE STATICdefinition ofstatic class


  'Gambas class file'   '   MatitaRossa CLASS   .   INHERITS Pencil   .   CREATE STATIC definitionunderstatic class


Unlike the made forCREATE PRIVATE, the new class MatitaRossayestakes on the properties of the upper classPencil, but there is Bisonó to create it, because he does automatically the Gambas interpreter to having the program, and the class is immediately available for use.

It 'obvious that, in this case, it is not possible to have, and then create multiple instances of the same object, so this approach has the basic purpose of: maintaining an object-oriented program management, and' Using a static class as a kind of container-specific features, then it is a bit like the form in Gambas.