Attributes (OOM)

An attribute is a named property of a class (or an interface) describing its characteristics.

An attribute can be created for a class or interface in the following diagrams:


A class or an interface may have none or several attributes. Each object in a class has the same attributes, but the values of the attributes may be different.

Attribute names within a class must be unique. You can give identical names to two or more attributes only if they exist in different classes.

In the following example, the class Printer contains two attributes: printspeed and laser:



Interface Attributes

An attribute of an interface is slightly different from an attribute of a class because an interface can only have constant attributes (static and frozen). For example, consider an interface named Color with three attributes RED, GREEN, and BLUE. They are all static, final and frozen.



If you generate in Java, you see:

public interface Color
{
 public static final int RED = 0xFF0000;
 public static final int GREEN = 0x00FF00;
 public static final int BLUE = 0x0000FF;
}

All these attributes are constants because they are static (independent from the instances), final (they can not be overloaded), and frozen (their value cannot be changed).

You can use the attributes of other interfaces or classes and add them to the current interface.


Created October 7, 2009. Send feedback on this help topic to Sybase Technical Publications: pubs@sybase.com