Namespaces

From FizzFuzz

Jump to: navigation, search

A namespace is a value used to indicate a specific grouping of classes, functions, and/or variables tied together by a specific reference. These can be used to seperate classes, variables, and functions from other things, where there would normally be naming conflict.

Contents

Defining A Namespace

Namespaces can be defined one of two ways, both involving the namespace keyword. One acts as a grouping mechanic, and the other is a class modifier. These two methods can be used in conjuction, and will cause no problem.

Grouping Mechanic

namespace __namespace__
    int variable = 5
 
    int method()
        return variable
 
    class __class__
        int bloop = 2
 
        int blarg()
            return bloop

Class Modifier

class __class__
    namespace __namespace__
 
    int bloop = 2
 
    int blarg()
        return bloop

Accessing A Namespace

Classes, methods, and variables of a namespace can be accessed by the :: operator. This takes the format of [namespace]::[function, variable, or class].

#include <std.dflt.*>
 
namespace __namespace__
    //Can only be accessed by members of this namespace.
    private var v = 200
 
    var read()
        return v
 
    void write(var n)
        v = n
 
void main()
     //Accesses __namespace__'s write() method, and changes
     //its value to 500.
    __namespace__::write(500)
 
    //This would output "500".
    environment.outputln(__namespace__::read())
Personal tools
Navigation
functions
language