* Programming Guide * CJDT User Guide * Publications * Tutorial * Language Spec.



Source Code


Community Info

About Us


ST Logo
TUD Logo
<< Expression Problem | Contents | >>

Subject-Oriented Views

In this example we show how virtual classes can be used to create and compose subject-oriented views [1].

Fig. 1: Two subjects having different views of the Forst

Let us consider the diagram in the Fig. 1. We have a world model consisting of different kind of plants (Maple, Cherry, Pine, etc.), birds and woodmen. We call this world, the Forest (see the gray framed area). Furthermore, we have two subjects having two different views on that world, namely the eagle and the woodman. Each subject categorizes the world from its own point of view. Using virtual classes we have separated the eagle concern from woodman concerns. By applying the &-operator we can compose these concerns to a single data model. Moreover, we can add interactions among the composed concerns. E.g., when a tree is chopped down by the woodman, its food value (relevant for the eagle) sinks to zero.

Although this example is rather of illustrative nature, it is of importance for the application integration. We could easily think about the forest as a business model for managing telephone tariffs, the eagle as GUI-Framework and the woodman as persistence manager.

public cclass Forest {
	public cclass Maple {}	
	public cclass Cherry {}	
	public cclass Locust {}	
	public cclass Pine {}
	public cclass Dandellon {}
	public cclass Bird {}
	public cclass Woodman {}
public cclass EagleSubject extends Forest {
	public cclass Plant {
		protected int foodValue;
		public void setFoodValue(int foodValue) {this.foodValue = foodValue;}
		public int getFoodValue() {return foodValue;}
	public cclass Nestable {
		private int nestSafetyRating;
		public void setNestSafetyRating(int val) {this.nestSafetyRating = val;}
		public int getNestSafetyRating() {return nestSafetyRating;}
	public cclass Predator {
		private int rating;
		public void setDangerRating(int rating) {this.rating = rating;}
		public int getDangerRating() {return rating;}
	public cclass NectarPlant extends Plant {}
	public cclass InsectPlant extends Plant {}	
	public cclass Maple extends Nestable {}	
	public cclass Cherry extends NectarPlant & InsectPlant & Nestable {}	
	public cclass Locust extends InsectPlant & Nestable {}	
	public cclass Pine extends InsectPlant & Nestable {}	
	public cclass Dandellon extends NectarPlant {}	
	public cclass Bird {}	
	public cclass Woodman extends Predator {
		private int attackingRating;
		public void setAttackingRating(int rating) {
			this.attackingRating = rating;
		public int getAttackingRating() {return attackingRating;}
public cclass WoodmanSubject extends Forest {
	public cclass Tree {
		private int timeToChopDown;
		public void setTimeToChopDown(int timeToChopDown) {
			this.timeToChopDown = timeToChopDown;
		public int getTimeToChopDown() {return timeToChopDown;}		
		public void chopDown() {}
	public cclass NonTree {}
	public cclass Softwood extends Tree {}	
	public cclass Hardwood extends Tree {}	
	public cclass Maple extends Hardwood {}	
	public cclass Cherry extends Hardwood {}	 
	public cclass Pine extends Softwood {}	
	public cclass Dandellon extends NonTree {}	
	public cclass Bird extends NonTree {}	
	public cclass Woodman extends NonTree {
		private int salary;
		public void setSalary(int salary) {this.salary = salary;}
		public int getSalary() {return salary;}
public cclass WoodmanEagleSubject extends WoodmanSubject & EagleSubject {
	public cclass Plant {}
	public cclass Tree extends Plant {
		public void chopDown() {

[1] W. Harrison and H. Ossher. Subject-oriented programming (A critique of pure objects). In Proceedings OOPSLA '93. ACM SIGPLAN Notices 28(10), pages 411-428, 1993.

<< Expression Problem | Contents | >>