Object

From StudyWiki

Jump to: navigation, search


Contents

General Concepts

Object
A data structure that models a physical object or an abstract concept. It is an instance of a class.



  • objects have properties (called attributes) and actions they can perform (called methods).
  • Before use, objects must first be declared (space allocated in memory) and then initialised (the actual creation of the object )
    • object declaration declares the name used to refer to the object and reserves memory for it, but does not create it.
      • (Like booking a table in a restaurant, you have a table set and you know who is sitting there, but they've not arrived yet)
    • object initialisation associates an existing object with the object name, or create a new object to associate it with.


UML Notation

Image:EmptyObjectNoClass.gifAn object without an associated class

Image:EmptyObject.gifAn object that belongs to a class, the colon separates the object and class names.

  • objects are shown using a rectangle.
  • Their names are underlined

Programming Languages

Java

Object Declaration

Object Declaration Syntax
<classname> <objectname> ;
<classname>
The name of the class the object(s) belong to.
<objectname>
The object's unique identifier.


Object Naming Conventions
  • Names can only contain letters, digits, underscores, or dollar signs.
  • Names are case sensitive.
  • First letter must be a lower case character.
  • Where names/identifiers have multiple words, the first letter of all words after the first will be upper case (don't use underscores for spaces).


  • To declare an object , its class must already be defined.
  • Multiple objects of the same class can be declared on the same line by separating each <objectname> with a comma:
<classname> <objectname> , <objectname> ;


Object Initialisation

Object Initialisation Syntax
<objectname> = new <classname> ( <arguements> ) ;
<objectname>
A valid, declared object identifier
<classname>
The name of the class to create
<arguments>
(Optional) Any arguments that the class requires when being initialised


  • The new keyword is used to create objects.
  • If an identifier currently in use is used to create a new object, the identifier will now refer to the new object, while the old object will eventually be deallocated by Java's garbage collection mechanism as it is no longer referred to.


VBA

  • Built-in objects are arranged into hierarchies and collections.
  • Attributes (called properties in VBA) are directly accessible (no accessor or mutator methods)
  • This means where objects are stored as properties of other objects, the properties and methods of the stored object can be accessed directly as well
    • For Example: Application.CurrentDb will return a reference to the current database, which is stored in a CurrentDb object, which is a property of the Application object.


Object Declaration

  • objects are declared in the same manner as variables, where the variable type is the name of the object being declared.


Object Initialisation

Object Initialisation Creating A New Object 
Set <objectname> = New <classname> ( <arguements> )
For Example
   Set objCatalog = New ADOX.Catalog


<objectname>
A valid, declared object identifier
<classname>
The name of the class to create
<arguements>
(Optional) Any arguments that the class requires when being initialised


Object Initialisation Using An Existing Object 
Set <objectname> = <existing object>
For Example
   dim ctlFirstName as Control
   Set ctlFirstName = TextBox


<objectname>
A valid, declared object identifier
<existing object>
The name of, or a reference to, an existing object.


  • To initialise an object use the Set keyword
  • An object can be initialised to refer to a new object , or an existing object
  • The types of the declared objectname and existing object or class must match.