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
- Variables
- type BaseFactory
- type BaseObject
- type BaseProxy
- type Callable
- type Child
- type ComposingContainer
- type Composite
- type CompositeCollection
- type CompositeFactory
- type Factory
- type Object
- type Parent
- type Proxy
- type Reference
- type ReferenceContainer
- type Resolver
- type ResolverHandler
- type ScopeType
Constants ¶
const ( ChildScope = ScopeType(iota + 1) ContextScope GlobalScope )
ChildScope, ContextScope and GlobalScope represents types of scope for references.
Variables ¶
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) GetClassID ¶ added in v0.0.3
GetClassID is a proxy call for instance method.
func (*BaseProxy) GetReference ¶ added in v0.0.3
GetReference is a proxy call for instance method.
func (*BaseProxy) SetReference ¶ added in v0.0.3
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 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 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 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 Reference ¶
type Reference interface { String() string GetRecord() string GetDomain() string GetScope() ScopeType }
Reference represents address of object.
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.