BDRule

Inherits from:
NSObject
Conforms to:
NSCoding
BDPropertyListEncoding (informal protocol)
Declared in:
BDRuleEngine/BDRule.h

Class at a Glance

A BDRule respresents a rule in the rule system.


Class Description

Each rule in the rule system is represented by an instance of BDRule.

Rules have three components: A left-hand side or condition, a right-hand side or assignment, and a priority.

The left-hand side of a rule is a qualifier - an instance of BDQualifier from the BDControl Framework - describing a condition under which the rule applies. All of the keys in this qualifier are relative to the BDRuleContext in which this rule is being evaluated. Qualifiers used in the left-hand sides of rules may not have any variables.

The right-hand side of a rule is an assignment - an instance of BDAssignment - that describes the result of "firing" the rule. It is composed of a key path and a value. When a BDRuleContext is asked for the value of a particular key, only rules whose right-hand side contains a matching key for its key path is consulted; the value of the most applicable rule's right-hand side is returned as the value for that key in the context.

A rule's priority determines how applicable it is in a given situation. Rules with higher priorities are considered by the rule system before rules with lower priorities. The magnitude of a rule's priority is unimportant, only whether it is less than, the same as, or equal to the priority of another rule with the same right-hand side key path.


Adopted Protocols

NSCoding
-encodeWithCoder:
-initWithCoder:
 
BDPropertyListEncoding (informal protocol)
-encodeIntoPropertyList:
-initWithPropertyList:owner:
-awakeWithPropertyList:

Method Types

Initialization
+ruleWithLhs:rhs:priority:
-initWithLhs:rhs:priority:
Accessors
-setLhs:
-lhs
-setRhs:
-rhs
-setPriority:
-priority
Firing
-fireInContext:

Class Methods

ruleWithLhs:rhs:priority:

+ (id)ruleWithLhs:(BDQualifier *)lhs rhs:(BDAssignment *)rhs priority:(int)priority

Returns an autoreleased rule with the corresponding left-hand side, right-hand side, and priority.


Instance Methods

fireInContext:

- (id)fireInContext:(BDRuleContext *)context

"Fires" the rule in the given context. This fires the rule's right-hand side assignment, and returns the result of firing the assignment.

initWithLhs:rhs:priority:

- (id)initWithLhs:(BDQualifier *)lhs rhs:(BDAssignment *)rhs priority:(int)priority

Initializes an instance of BDRule with the corresponding left-hand side, right-hand side, and priority.

lhs

- (BDQualifier *)lhs

Returns the left-hand side qualifier of the rule.

priority

- (int)priority

Returns the priority of the rule.

rhs

- (BDAssignment *)rhs

Returns the right-hand side assignment of the rule.

setLhs:

- (void)setLhs:(BDQualifier *)value

Assigns a new left-hand side qualifier to the rule.

setPriority:

- (void)setPriority:(int)value

Assigns a new priority to the rule.

setRhs:

- (void)setRhs:(BDAssignment *)value

Assigns a new right-hand side assignment to the rule.


Copyright © 2002, 2003 bDistributed.com, Inc. All rights reserved worldwide.