"using" directive, static classes, proper examples, declared objects are nom recommanded to be accessed using the $ prefix like all other variables.
This commit is contained in:
parent
66bfe1d2c4
commit
d4a7290707
3 changed files with 32 additions and 6 deletions
|
@ -5,3 +5,6 @@ namespace Example
|
||||||
|
|
||||||
# Object declaration, from class name to file name.
|
# Object declaration, from class name to file name.
|
||||||
class Object "Object.shc"
|
class Object "Object.shc"
|
||||||
|
|
||||||
|
# Static class declaration
|
||||||
|
static_class Static "Static.shc"
|
||||||
|
|
6
example/Static.shc
Normal file
6
example/Static.shc
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
|
||||||
|
# Function declaration.
|
||||||
|
# NOTE: Properties can't be declared for static classes
|
||||||
|
Static.print() {
|
||||||
|
echo "$@"
|
||||||
|
}
|
|
@ -3,14 +3,31 @@ OOP_ROOT=..
|
||||||
|
|
||||||
. $OOP_ROOT/oop.sh # Import library.
|
. $OOP_ROOT/oop.sh # Import library.
|
||||||
|
|
||||||
|
# Import library
|
||||||
importNamespace Example.shn
|
importNamespace Example.shn
|
||||||
|
|
||||||
Example.Object t1 "Test"
|
# OOP Example
|
||||||
Example.Object t2 "Example"
|
Example.Object obj1 "First Object"
|
||||||
|
Example.Object obj2 "Second Object"
|
||||||
|
|
||||||
t1.print
|
$obj1.print
|
||||||
t2.print
|
# The $ is not mandatory, but is recommanded.
|
||||||
|
obj2.print
|
||||||
|
|
||||||
t1.name = "New name"
|
objs=($obj1 $obj2)
|
||||||
|
${objs[0]}.print
|
||||||
|
${objs[1]}.print
|
||||||
|
|
||||||
t1.print
|
$obj1.name = "New name"
|
||||||
|
|
||||||
|
$obj1.print
|
||||||
|
|
||||||
|
# Static example
|
||||||
|
Example.Static.print "Example text"
|
||||||
|
|
||||||
|
# Using directive.
|
||||||
|
using Example
|
||||||
|
|
||||||
|
Object usingObj "New"
|
||||||
|
|
||||||
|
$usingObj.print
|
||||||
|
|
Loading…
Reference in a new issue