Articles Tagged 'instance'

Very short trick: how to use NSFileManager

, in quanto quest'ultimo restituisce un'instanza singleton, cioè sempre lo stesso puntatore ad oggetto (non thread safe). Apple recommends using the object instance NSFileManager and not its meotodo class defaultManager , as the latter returns an instance singleton, that is always the same pointer to the object (not thread safe).

More ...

Classes, Objects and Instances

I noticed often confusion when it comes to classes, objects and instances. Who is not particularly educated on object-oriented programming often confuses the true meaning of these terms. I knew, however, that there are two schools of thought regarding the definition of Class and Object. I like the "school" that indicates the class definition as a possible subject, and thus the object as instance of the class.

It sounds simple, but it happened to me - talking with others - to be in "conflict" (so to speak) and then fall into confusion, when using these terms, if anything, starting from the premise that "the other" just as we intend them .

I see it in this way, a class is a definition! Is precisely defined class of possible objects. The class is the set of methods and properties (if you want we can also add events - what else ... not only that special methods) that will own the object.

For example, when we write in Actionscript, or any other object-oriented language:

1
2
3
4
class MyClass {
MiaClass function () {}
function myMethod () {}
}

We have defined a class and not an object. In the limit we have "defined" a "possible" object. We could even argue, and rightly, that the object exists at runtime while Class not (in truth there are dynamic classes that can be defined - and then used to create objects - even at runtime). Exclude static classes, of course, that - eventually - are nothing more than sub-instances (or instances hidden) and real objects.

But when we:

1
MiaClasse = new MiaClasse ( ) ; var MyObject: MyClass = new MyClass ();

! Here mioOggetto is an instance of MiaClasse() ! . That mioOggetto is a subject - in fact - of type MiaClasse() .

. Consequently, their philosophy to objects, objects of type MiaClasse() I can have as many as I want, something that can not be - the very definition - of MiaClasse() . For example, if applies and it makes sense to the relation:

1
2
3
4
5
MiaClasse = new MiaClasse ( ) ; var mioOggetto_1: MyClass = new MyClass ();
MiaClasse = new MiaClasse ( ) ; var mioOggetto_2: MyClass = new MyClass ();
MiaClasse = new MiaClasse ( ) ; var mioOggetto_3: MyClass = new MyClass ();
...
MiaClasse = new MiaClasse ( ) ; var mioOggetto_n: MyClass = new MyClass ();

It makes no sense:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class MyClass {
MiaClass function () {}
MioMetodo_2 function () {}
}

class MyClass {
MiaClass function () {}
MioMetodo_2 function () {}
}

class MyClass {
MiaClass function () {}
MioMetodo_3 function () {}
}

Object Instance and, therefore, coincide and are used alternately for the same meaning in different contexts.

Probably not much care about anyone ... the question needs to be complete ... :)

More ...


Stop SOPA