Inheritance Concept in WebLord, the Document Assembly Tool
Logo WebLord v2.2
The Document Assembly Tool

Inheritance

Inheritance is an object-oriented concept by which one object inherits one or more properties from its parent object (the object that referenced it) if and only if the object does not define these properties.

As such definitions go, it is usually better to give an example. Let's define an object named Mother and another object named Daughter. The object Mother will reference the Daughter object:

	Mother:
		hair = "blonde"
		face = "oval"
		eyes = "green"


	Daughter:
		face = "narrow"

Notice that the Daughter object defines only a property named face. If, as we claimed, the Daughter object inherits properties from its parent (Mother in this case), then Daughter will inherit hair and eyes from its parent, but not face!

The Daughter object already defines face. This means that it cannot inherit this from its parent.

Let us next define another object and assume that it references Mother, and (as before) that Mother references Daughter:

	Grandma:
		body = "athletic"
		hair = "blonde"
		fingers = "long"
Question:       What is the complete set of properties of the Daughter object?
 
Answer:      
face = "narrow"
hair = "blonde"		inherited from Mother
eyes = "green"		    "      "     "
body = "athletic"	inherited from Grandma
fingers = "long"	    "      "      "

If you followed and understood the above, then you now understand inheritance of properties, one of the key concepts that WebLord uses!

Rather than continue to use a pseudo-format for the objects, let's try a more complicated example with WebLord's real object format. You can actually cut-and-paste this into a file, then build the file and get a result!

	# The SITE object is always required; its name doesn't matter.
	#	- The PAGES property lists the pages to be built
	#	- The OUTPUT property defines the name of the output file
	#	- The TITLE property is just something we've added; WebLord
	#	  doesn't treat it special
	site = main
	{
		pages=  Page1 Page2 Page3;
		output = page.objectname ".html";
		title=  "<title>Default Page Title</title>";
	}

	# This is a TEXT object whose value is simply a constant string
	text = funny-title
	{
		value = "<title>We are NOT eskimos!</title>";
	}

	# A PAGE object (Page1) with a VALUE that references a TITLE.
	#	The page defines a TITLE property, so it won't inherit it.
	page = Page1
	{
		value=  "<html><head>" title "</head><body>Test for page 1</body>"
			"</html>";
		title=     "This is a specific title for page #1";
	}

	# A PAGE object (Page2) with a VALUE that references a TITLE.
	#	The page doesn't define a TITLE property, so it will have to inherit it
	page = Page2
	{
		value = "<html><head>" title "</head><body>"
			"test for page 2</body></html>";
	}

	# A PAGE object (Page3) with a VALUE that references a FUNNY-TITLE
	#	The page doesn't define a FUNNY-TITLE, and neither do any of
	#	its parent objects (the SITE in this case); there is, however
	#	a TEXT OBJECT named FUNNY-TITLE, so this object is evaluated
	#	and that becomes the value for the FUNNY-TITLE!!
	page = Page3
	{
		value = "<html><head>" funny-title "</head><body>"
			"Test for page 3</body></html>";
	}

	# A PAGE object (Page4) with a VALUE that references a MISSING-TITLE
	#	The page doesn't define a MISSING-TITLE; neither does any of
	#	its parent objects; there also is NO object with that name,
	#	so the value of MISSING-TITLE is simply "" (nothing)
	page = Page4
	{
		value = "<html><head>" missing-title "</head><body>"
			"Test for page 4</body></html>";
	}
What's actually happening with the 'title' properties?

The page object 'Page1' defines a 'title' property, so this title is used directly from the object that referenced it.

The page object 'Page2' does not define a 'title' property, but it inherits the 'title' property from the object's parent (the SITE object 'main') which defines it.

The page object 'Page3' references a 'funny-title' property. It doesn't define this, and neither does any of its parent objects define such a property. There is, however, an object by that name! That object is now evaluated, which results in a value for the title for Page3.

The page object 'Page4' references a 'missing-title' property. Again, it doesn't define such a property, and neither does any of its parent objects. Alas, there is no object by that name, either. For this reason, the reference to 'missing-title' will simply produce no value at all.

Why does the last case not produce an error?

The reason is that there are many cases where something should evaluate to a some value at one point but have no value at other times. If you need to know when a reference to an object failed to locate it, you should use the debug argument when you run WebLord: it will, among other things, inform you of any reference to an undefined object.

Are all properties inheritable?

No! The middle column of the Site Object, Page Object, and Text Object descriptions specify one of three attributes for inheritance:

yes Inherited without limitations, unless marked private
explicit Inherited only if marked inheritable
never Never inherited!

A Graphical Representation of Inheritance

The following image demonstrates three cases of inheritance:

Inheritance

Three scenarios are depicted in the image above. In each, one object ("Grandparent") calls an object ("Parent"), which in turn calls another ("Current Object"); it is from the perspective of this latter ("current") object that we examine the effect of inheriting properties:

  1. Properties (A) and (B) are inherited all the way back from the "Grandparent" object. This is because neither the current object, nor the Parent object define these. The property (C) is inherited from the Parent object.

  2. Property (A) is inherited from the Grandparent, property (C) from the Parent. The current object defines a property (B) of its own, which is, therefore not inherited from any ancestor (none define it, in this case anyway.)

  3. Property (A) is again inherited from the Grandparent, property (C) is inherited from the Parent. Notice that the Parent re-defined property (C), so the Grandparent's definition is effectively hidden; the current object has no way of knowing whose definition of the property (C) it actually gets.

This material is Copyright © 1997,1998,1999,2000,2001 RingLord Technologies and Udo Schuermann. All rights reserved. The latest versions of the WebLord software and (this) documentation can be obtained from the WebLord Home Page (the link will only function if you are connected to the internet.)