Browse Prior Art Database

Providing class-level fallbacks for null object-level methods and properties. Disclosure Number: IPCOM000219384D
Publication Date: 2012-Jun-27
Document File: 8 page(s) / 64K

Publishing Venue

The Prior Art Database


This article presents a potential language feature which assists developers in encapsulation of behaviour. In many languages, invoking methods (or accessing properties) on objects that do not exist (e.g., a null reference in C++) will cause an exception. The proposal in this article allows a developer to protect against this situation in circumstances where more rational behaviour may be to provide a special case for it. It does so by providing class-level fallbacks for null object-level methods and properties.

This text was extracted from a PDF file.
This is the abbreviated version, containing approximately 27% of the total text.

Page 01 of 8

Providing class-level fallbacks for null object-level methods and properties.

1. Introduction to classes and objects.

In the object oriented programming paradigm, a developer creates classes which are then used as a template for creating individual objects.

The class specification details the behaviour of the objects such as their methods (functions which can act on the objects) and their properties (the state of an individual object). In all cases below where we discuss methods, the descriptions should also be read to include properties.

A simple case is a two-dimensional co-ordinate, the specification for an object that holds a X and Y value for a given point:

class Point:

// The co-ordinates of the point.

private property float xcoord;

private property float ycoord;

// For creating a point object.

public method

constructor (float x, float y):

me.xcoord = x;

me.ycoord = y;

// Return the X or Y co-ordinate.

public method

getX ()

returns float:

return me.xcoord

public method

getY ()

returns float:

return me.ycoord

One of the major advantages of object oriented programming is that of encapsulation (or information hiding). By only publishing the minimal amount of detail necessary for client code to use a class, developers are free to do whatever they wish in the internals of the class (such as use more efficient algorithms)

without breaking the"contract" with the users of that class. This leads to minimal coupling between objects and therefore better programming practices.


Page 02 of 8

When you create a specific object based on a class, there are generally two types of methods which an class provides.

The first can be called an object-level method. This type of method requires an actual object to work on, since it generally uses the object properties. The second can be called a class-level method, which does not require an actual object but instead acts on class-level properties only, or no properties at all.

Consider a Circleclass as follows:

class Circle:

// The middle and radius of the circle.

private property float xcoord;

private property float ycoord;

private property float radius;

// Constructor to make a circle object.

public method

constructor (float x, float y, float r):

me.xcoord = x;

me.ycoord = y;

me.radius = r;

// Calculate area of arbitrary radius.

public class_level method

calcArbArea (float r)

returns float:

return PI * r * r;

// Calculate area of this circle.

public method

getArea ()

returns float:

return PI * me.radius * me.radius;

along with the following code segment:

Circle xyz = new Circle (0, 0, 10);

float areaA = Circle.calcArbArea (22);

float areaB = xyz.getArea ();

In this example, there are two ways to work out the area of a circle. The first, calcArbArea, is a class-levelmethod that doesn't require an actual object to


Page 03 of 8

exist, and you can give it any radius to use for the calculation. This may be useful in circumstances where you don't want or need to actually create an object to do some...