ClassHandler-1.0

Getting Started

Before starting to use ClassHandler, I strongly recommend to learn how to work with EmbedHandler-1.0.

What is ClassHandler?

The main goal of ClassHandler is to provide an easy way to create object which share all the same methods, in a similar way how frame classes behave. Look at the following example:

-- Creates a new class
local Class = ClassHandler:NewClass('MyClass')

function Class:NewObject()
  -- Creates a new frame and embeds all the methods from the class into it
  local object = CreateFrame('Frame')
  return Class:Embed(object)
end

function Class:SomeMethod()
  -- Some method
end

function Class:OtherMethod()
  -- Other method
end

This example creates a virtual class, and then, defines an important method: 'NewObject', which returns a frame and embeds all the class methods ('SomeMethod', 'OtherMethod') into it.

When creating frames, ClassHandler-1.0 also works great with Blizzard's UIFrameCache:

-- Creates a new UIFrameCache, and registers it as a class
local Cache = FrameCache:New('Frame', 'MyFrame')
ClassHandler:NewClass('MyClass', Cache)

function Cache:NewObject()
  -- Calls a new frame trough the cache
  local object = self:GetFrame()
  return Cache:Embed(object)
end

Acessing ClassHandler

The easiest way to access ClassHandler-1.0 methods is to embed them into your addon object.

local ClassHandler = LibStub("ClassHandler-1.0")
ClassHandler:Embed(MyObject)

But you may also set ClassHandler as a local variable and call the methods directly.

ClassHandler.NewClass('MyClass')

Next page (API) ->>

You must login to post a comment. Don't have an account? Register to get one!

Facts

Date created
Dec 09, 2009
Last updated
Dec 10, 2009

Author