Objects and Inheritance
Using objects lets us define static facts, represent generalities, and write more powerful and expressive rules.
[Course Home Page]
[CIS Dept]
[Business School]
[University
of Michigan]
1) Uses of and motivations behind objects and inheritance
- 1) They mimic the way we think (in categories; not each case separately).
- 2) They allow much more elegant, expressive, understandable knowledge
bases.
- 3) KB maintenance is far easier.
2) Fundamental distinctions
- We will focus on ISA hierarchies. (AKA: abstraction hierarchies).
- Compare to: HAS hierarchies (AKA: aggregation hierachies).
- Heuristic: for each link (bottom to top), you should be able to say
"child ISA parent" and have that make sense.
3) Building blocks
- Abstraction hierachies are composed of
Classes.
- Classes can be subdivided into additonal Classes (sub-classes) until,
finally, we arrive at:
- Instances (which are at the bottom level
of any hierachy).
- Sorry: I can't create a suitable graphic to put in here. It would show:
- animal: top-level class
- bird and elephant: as second level classes
- robin and crow: as sub-classes of bird
- and these instances as "leaves": Tweety, Trixie
(robins); Blackie (crow); Clyde and
Jumbo (elephants)
- Attributes
- Basic idea (example): All animals have Heights, Weights, and Ages.
Thus (if these are useful attributes for our problem), define them ONCE
(and for all) for Animals.
- Then, by inheritance: the classes bird,
elephant, robin, and crow have these attributes.
- And so do all instances.
- Different classes can have different attributes.
- Example: wing-span is a good attribute for birds, not for animals.
Define it for birds.
- Values
- Basic idea: Establish "default"
(commonly expected values) at as general a level as possible
- (This means: as "high up" in the hierarchy as possible)
- Example: if you want to set a value for the attribute "breathes
Oxygen," set it to True for Animals, instead of setting it true separately
for birds and elephants.
- Use: "exceptions" to over-ride
defaults.
- Example: set Num Tusks = 2 for the Class elephants. Set Jumbo | Num
Tusk = 1 if one of his fell off!
- Exceptions to exceptions are possible, too.
4) Building Hierachies
- Establish that your prooblem has exploitable generality
- Identify classes involved and arrange them in hierachy.
- can have two hierachies. E.g.: one for customers; another for products
- Establish (i.e, define) attributes at the appropriate, highest possible
(most general) level.
- Set values for attributes at the highest possible level, too.
- If you know values even before you ask a user questions, set them for
appropriate object | attributes.
- Never re-define attributes at lower levels
- eg: if you defined Num legs as an attribute for Animals, don't redine
it for elephants
- let inheritance do it this instead
- Note: understand the difference between defining attributes and setting
values
- the value for an attribute may be set and re-set at different levels
of the hierachy (this corresponds to having defaults and exceptions)
5) Class Rules
- Definition: Rules that mention Classes (rather than instances)
- Use: short-hand for rules that mention instances. Ie., write
one rule; have it do the work of many. This gives your ES power!
- Examples (all valid):
- IF VCR | cost < 300 THEN recommendation is buy from our store /*
VCR is a Class */
- Short hand for:
- IF VCX-1 | cost < 300 THEN recommendation is buy from our store
/* VCX-1 is instance */
- IF VCX-2 | cost < 300 THEN recommendation is buy from our store
/* another instance */
- etc.
- IF customer | max price will spend > <VCR | price> THEN recommendation
is consider /* VCR = class */
- IF customer | purchase category is electronics THEN VCR | acceptability
is a possibility /* still a class */
- IF VCR | price < <Customer | max price will pay> AND ... THEN
recom is objectname(<VCR>)
- Note: "bindings" are consistent.
- E.g.: If VCR | price < 300 THEN purchase | pricewith
tax = <VCR | price> * 1.06 refers to
- VCX-1 twice: If VCX-1 | price < 300 THEN purchase | pricewith
tax = <VCX-1 | price> * 1.06
- VCX-2 twice; and
- Beta-Junior twice;
- but is NOT shorthand for If VCX-1 |
price < 300 THEN purchase | pricewith tax = <VCX-2
| price> * 1.06