Home About Rice Downloads Documents Others Cooker CookerGX
Documents  >  Tutorial  >  methods
Method

Purpose of this chapter.

We will learn about the method which is the basic elements that make up the class definition.

Method

The method is the interface to call the class member. It use the format of the function call. The main purpose is to specify the behavior of the class.

First, let us look at the method definition part of Circle.88.

1:

// -----------------------------------------------Methods.

2:

// It draws a circle.

3:

open method void Draw()

4:

_box.Style.Clear(); // It clears the position.

5:

_doc.InvokeJS("drawCircle", _x, _y, _radius); // invokes javascript. It draws a circle to the canvas element.

6:

endmethod

7:
8:

// It removes a circle.

9:

open method void Clear()

10:

_doc.InvokeJS("clearCircle"); // invokes javascript. It removes a circle from the canvas element.

11:

endmethod

12:
13:

// It does not redraw a circle. It will move _box element.

14:

open method void Move()

15:

_top = _y - _radius;

16:

_left = _x - _radius;

17:
18:

_tt.Start();

19:

endmethod

20:
21:

// This method is handler that is invoked from the timer.

22:

// It does not redraw a circle. It will move _box element.

23:

open method void timerHandler(timer tt)

24:

//If the circle reaches boundary, moving direction will change.

25:

if(_top<= 0 | (_top + _radius * 2) >= 600) //600 is height of display area.

26:

_ver = _ver * -1;

27:

endif

28:

if(_left<= 0 | (_left + _radius * 2) >= 600) //600 is width of display area.

29:

_hor = _hor * -1;

30:

endif

31:
32:

// The top-left corner.

33:

_top = _top + _ver;

34:

_left = _left + _hor;

35:
36:

// The center.

37:

_x = _left + _radius;

38:

_y = _top + _radius;

39:
40:

// Shows the coordinate of the center.

41:

_doc.InvokeJS("setInputValue", "center_x", _x);

42:

_doc.InvokeJS("setInputValue", "center_y", _y);

43:
44:

// moves position.

45:

_box.Style.SetRuntimeAttribute("top", _top.ToString() + "px");

46:

_box.Style.SetRuntimeAttribute("left", _left.ToString() + "px");

47:

endmethod

48:
49:

// It stops moving.

50:

open method void Stop()

51:

_tt.Stop();

52:

endmethod

A definition of the method is the following format.


access-control(open or closed) method return-value-type method-name ( arguments... )

Statements of the method definition...

endmethod


The method definition is the definition that starts with access control and the 'method' keyword. And, it ends with 'endmethod' keyword.

Access control

The access level of the method will be specified using the 'open' or 'closed' keyword.

If the 'open' keyword is specified, the method can be used anywhere in the program.

If the 'closed' keyword is specified, the method is available only the inside of the class definition.

The 'method' keyword indicates that this definition is a method definition. It must be specified at the next of the access-control.

Return value type

A type of the return value must be specified at the next of the 'method' keyword. It indicates a class name of an instance that will be returned from a method.

If the method does not return a value, please specify the void.

Method name

The method-name must specify at the next of the return-value-type. The naming rule of the method name is the same as the identifier.

A method of the same name that has different arguments can be defined.

e.g.


open method int Sample(int value)

return Value;

endmethod

open method long Sample(long value)

return Value;

endmethod


The corresponding method to the arguments will be called even if method name is the same.

Arguments

The arguments of the method must be specified at the next of the method-name, it must be enclosed by parentheses.

The arguments are specified by the set of class-name (type of the argument) and argument-name.

If there are two or more arguments, those are separated by a comma. If number of the argument is one, comma is not required. If there is no argument, inside of the parentheses is empty.

Rice will distinguish the method that has the same name by the order of the type of argument. The method that has the same name and the different arguments can be defined any number.

The Rice creates a name for calling a method from the method name and the arguments.

e.g.

open method int A() -> "A()"

open method int A(int value) -> "A(int)"

closed method int A(int iVal, string sVal) -> "A(int,string)"


Please note that the access control and the return value type do not related to the generation of the name.

endmethod keyword

The 'endmethod' keyword indicates the end of the method definition.

Next
Previous
Copyright © Rice All rights reserved.