Class and Object Functions

class

Object creation.

Syntax

object = class(strct, 'classname')
object = class(strct, 'classname', parent1, ...)
str = class(object)

Description

class(strct,'classname') makes an object of the specified class with the data of structure strct. Object fields can be accessed only from methods of that class, i.e. functions whose name is classname::methodname. Objects must be created by the class constructor classname::classname.

class(strct,'classname',parent1,...) makes an object of the specified class which inherits fields and methods from one or several other object(s) parent1, ... Parent objects are inserted as additional fields in the object, with the same name as the class. Fields of parent objects cannot be directly accessed by the new object's methods, only by the parent's methods.

class(object) gives the class of object as a string. The table below gives the name of native types.

ClassNative type
doublereal, complex, or logical scalar or array
charcharacter or character array
listlist or structure
inlineinline function
funreffunction reference

Examples

o1 = class(struct('fld1', 1, 'fld2', rand(4)), 'c1');
o2 = class(struct('fld3', 'abc'), 'c2', o1);
class(o2)
  c2

See also

map, isa, isobject, methods

isa

Test for an object of a given class.

Syntax

b = isa(object,'classname')

Description

isa(object,'classname') returns true of object is an object of class class, directly or by inheritance.

Example

isa(pi,'double')
  true

See also

class, isobject, methods

isobject

Test for an object.

Syntax

b = isobject(a)

Description

object(a) returns true if a is an object created with class.

See also

class, isa, isstruct

methods

List of methods for a class.

Syntax

methods classname
list = methods('classname')

Description

methods classname displays the list of methods defined for class classname. Inherited methods and private methods are ignored. With an output argument, methods gives produces a list of strings.

See also

class, info


Copyright 1998-2007, Calerga.
All rights reserved.