object

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 18, 2018 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package object provides basic interfaces and default implementations of them. Provides reference interface and types of reference scope.

Usage:

domain := "1"
record := "1"
ref, err := NewReference(domain, record, GlobalScope)

Provides factory interface for factories of all objects and proxy objects.

Usage:

type someFactory struct {}

func (f *someFactory) GetClassID() string {
	return "someFactory"
}

func (f *someFactory) GetReference() object.Reference {
	return f.Reference
}

func (f *someFactory) Create(parent object.Callable) (object.Callable, error)
	// do creation logic
}

func main() {
	factory := someFactory{}
	obj := factory.Create(parent)
}

Provides resolver interface and default implementation of resolvers for getting objects from references. Interface Resolver uses interface{} type for reference, class and proxy (which GetObject returns), because in future implementation its going to be plugin. Virtual machine will be use it and provide resolving logic.

Usage:

resolver := NewChildResolver(parent)
obj, err := resolver.GetObject(ref, class.ObjectID)
res := obj.(object.Object)

Proxy provides interface and default implementation of proxy. It inherited by SmartContractProxy and Factory

Usage:

proxy := &BaseProxy{}

proxy.SetReference(Reference) sets reference to proxy.
proxy.GetReference() gets reference from proxy.
proxy.GetParent() always returns nil.
proxy.GetClassID() is a proxy call for instance method.

ReferenceContainer provides methods for store Reference as Proxy

Usage:

ref, _ := object.NewReference(domain, record, object.GlobalScope)
container = NewReferenceContainer(ref)

container.GetClassID()         // return string representation of object's class.
container.GetStoredReference() // returns stored reference.

Index

Constants

View Source
const (
	ChildScope = ScopeType(iota + 1)
	ContextScope
	GlobalScope
)

ChildScope, ContextScope and GlobalScope represents types of scope for references.

Variables

View Source
var GlobalResolver = newGlobalResolver()

GlobalResolver is a public globalResolver instance for resolving all global references.

Functions

This section is empty.

Types

type BaseFactory added in v0.0.3

type BaseFactory struct {
	BaseProxy
}

type BaseObject

type BaseObject struct {
}

BaseObject is a base implementation of Object interface.

func (*BaseObject) GetClass added in v0.0.3

func (bo *BaseObject) GetClass() Proxy

func (*BaseObject) GetClassID

func (bo *BaseObject) GetClassID() string

GetClassID return string representation of object's class.

type BaseProxy added in v0.0.3

type BaseProxy struct {
	// contains filtered or unexported fields
}

BaseProxy is a base implementation of Proxy.

func (*BaseProxy) GetClass added in v0.0.3

func (bp *BaseProxy) GetClass() Proxy

func (*BaseProxy) GetClassID added in v0.0.3

func (bp *BaseProxy) GetClassID() string

GetClassID is a proxy call for instance method.

func (*BaseProxy) GetParent added in v0.0.3

func (bp *BaseProxy) GetParent() Parent

GetParent always returns nil.

func (*BaseProxy) GetReference added in v0.0.3

func (bp *BaseProxy) GetReference() Reference

GetReference is a proxy call for instance method.

func (*BaseProxy) SetReference added in v0.0.3

func (bp *BaseProxy) SetReference(reference Reference)

SetReference is a proxy call for instance method.

type Callable

type Callable interface {
	Object
}

Callable is a marker interface that shows that object is able to be called.

type Child

type Child interface {
	Callable
	GetParent() Parent
}

Child allows to be created inside object (smart contract).

type ComposingContainer

type ComposingContainer interface {
	CreateComposite(compositeFactory CompositeFactory) (Composite, error)
	GetComposite(interfaceKey string, class CompositeFactory) (Composite, error)
	GetOrCreateComposite(compositeFactory CompositeFactory) (Composite, error)
}

ComposingContainer allows to store composites.

type Composite

type Composite interface {
	GetInterfaceKey() string // string ID of interface/type of Composite object; basically, GetClassID()
}

Composite marks that instance have ability to be compose in another object.

type CompositeCollection added in v0.0.3

type CompositeCollection interface {
	Composite
	GetList() []Composite
	Add(composite Composite)
}

type CompositeFactory

type CompositeFactory interface {
	Proxy
	Create(parent Parent) (Composite, error)
	GetInterfaceKey() string // string ID of interface/type of Composite object; basically, GetClassID()
}

CompositeFactory allows to create new composites.

type Factory added in v0.0.3

type Factory interface {
	Proxy
	// Create returns new instance of specified type.
	Create(parent Parent) (Proxy, error)
}

Factory allows to create new objects with reference.

type Object

type Object interface {
	GetClassID() string
	GetClass() Proxy
}

Object marks that instance has ClassID (string representation of class).

type Parent

type Parent interface {
	Callable
	GetChildStorage() storage.Storage     // Storage for child references
	AddChild(child Child) (string, error) // return key for GetChild func
	GetChild(key string) (Child, error)   // child type reference
	GetContext() []string                 // Parent give information about context references to its children
	GetContextStorage() storage.Storage   // Storage for context references
}

Parent allows to create objects (smart contracts) inside itself as children.

type Proxy added in v0.0.3

type Proxy interface {
	Child
	GetReference() Reference
	SetReference(reference Reference)
}

Proxy marks instance as proxy object.

type Reference

type Reference interface {
	String() string
	GetRecord() string
	GetDomain() string
	GetScope() ScopeType
}

Reference represents address of object.

func NewReference

func NewReference(domain string, record string, scope ScopeType) (Reference, error)

NewReference creates new reference instance.

type ReferenceContainer added in v0.0.3

type ReferenceContainer struct {
	BaseProxy
	// contains filtered or unexported fields
}

ReferenceContainer is a implementation of Proxy for containerization purpose.

func NewReferenceContainer added in v0.0.3

func NewReferenceContainer(ref Reference) *ReferenceContainer

NewReferenceContainer creates new container for reference.

func (*ReferenceContainer) GetClass added in v0.0.3

func (rc *ReferenceContainer) GetClass() Proxy

func (*ReferenceContainer) GetClassID added in v0.0.3

func (rc *ReferenceContainer) GetClassID() string

GetClassID return string representation of object's class.

func (*ReferenceContainer) GetStoredReference added in v0.0.3

func (rc *ReferenceContainer) GetStoredReference() Reference

GetStoredReference returns stored reference.

type Resolver added in v0.0.3

type Resolver interface {
	GetObject(reference interface{}, cls interface{}) (interface{}, error)
}

Resolver marks that instance have ability to get proxy objects by its reference.

type ResolverHandler added in v0.0.3

type ResolverHandler struct {
	// contains filtered or unexported fields
}

ResolverHandler should resolve references from any allowed scopes.

func NewResolverHandler added in v0.0.3

func NewResolverHandler(p interface{}) *ResolverHandler

NewResolverHandler creates new ResolverHandler instance.

func (*ResolverHandler) GetObject added in v0.0.3

func (r *ResolverHandler) GetObject(reference interface{}, class interface{}) (interface{}, error)

GetObject resolves object by its reference and return its proxy.

func (*ResolverHandler) InitGlobalMap added in v0.0.3

func (r *ResolverHandler) InitGlobalMap(globalInstanceMap *map[string]Proxy)

InitGlobalMap sets globalInstanceMap into globalResolver.

type ScopeType

type ScopeType int

ScopeType represent type of scope for references.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL