object instance question?

  • Thread starter Thread starter serge calderara
  • Start date Start date
S

serge calderara

Dear all,

One question related to instance creation.
Does an obejvt can create instance of its own ?

I mean if I have a class named User.

If I have a function named AddUser which is a public
function of the user class, dows the following is
something good to do :

function AddUser () as User

dim m_objUser = new Me
return m_objectUser
end function

Or is it better that the new instance object is
initialised from the main application.

thanks fro your answer
regards


thnakd for your answer
 
thnaks for your answer,

That was strange for me that a class create is own constructor inside
itself, it was more logic for me that tzhe constructor was called from
the application itself but oustide the class...

serge
 
Use
dim m_objUser=new User()

Where you call constructor is application dependent. Generally speaking it
doesn't matter.

HTH
Alex
 
You may want to consider some of the creational patterns

All of the creational patterns deal with the best way to create instances of
objects. This is important because your program should not depend on how
objects are created and arranged. In Java, of course, the simplest way to
create an instance of an object is by using the new operator.

The Factory Method provides a simple decision making class which returns one
of several possible subclasses of an abstract base class depending on data
it is provided.

The Abstract Factory Method provides an interface to create and return one
of several families of related objects.

The Builder Pattern separates the construction of a complex object from its
representation, so that several different representations can be created
depending on the needs of the program.

The Prototype Pattern starts with an initialized and instantiated class and
copies or clones it to make new instances rather than creating new
instances.

The Singleton Pattern provides a class of which there can be no more than
instance, and provides a single global point of access to that instance.


Wade
 
You may want to consider some of the creational patterns

All of the creational patterns deal with the best way to create instances of
objects. This is important because your program should not depend on how
objects are created and arranged. In Java, of course, the simplest way to
create an instance of an object is by using the new operator.

The Factory Method provides a simple decision making class which returns one
of several possible subclasses of an abstract base class depending on data
it is provided.

The Abstract Factory Method provides an interface to create and return one
of several families of related objects.

The Builder Pattern separates the construction of a complex object from its
representation, so that several different representations can be created
depending on the needs of the program.

The Prototype Pattern starts with an initialized and instantiated class and
copies or clones it to make new instances rather than creating new
instances.

The Singleton Pattern provides a class of which there can be no more than
instance, and provides a single global point of access to that instance.


Wade
 
Back
Top