HomeDigital EditionSys-Con RadioSearch Java Cd
Advanced Java AWT Book Reviews/Excerpts Client Server Corba Editorials Embedded Java Enterprise Java IDE's Industry Watch Integration Interviews Java Applet Java & Databases Java & Web Services Java Fundamentals Java Native Interface Java Servlets Java Beans J2ME Libraries .NET Object Orientation Observations/IMHO Product Reviews Scalability & Performance Security Server Side Source Code Straight Talking Swing Threads Using Java with others Wireless XML
 

"Core Object Principles in OO Programming"
Vol. 9, Issue 1, p. 34

	



Listing 1

public class Automobile {
	private String manufacturerName;

	public Automobile() {
	}

	public String getManufacturerName() {
		return manufacturerName;
	}

	public void setManufacturerName(String manufacturerName) {
	this. manufacturerName = manufacturerName;
}

public void drive() {
	... drive behavior ...
}
}

Listing 2

public class Automobile {
	
... other variables...
	
public void brake()
{
	... brake behavior ...
}

... other methods ...
}

public class DriversEducationAutomobile extends Automobile {
	public void brakeUsingInstructorsPedal()
	{
		... specialized Instructor braking behavior ...
		brake();
	}
}

Listing 3

public class AutomobileWithABS extends Automobile {
public void brake() {
		if (some condition warrants engaging the ABS system)
		{
			triggerABS();
		}
		else
		{
			super.brake();
		}
}	
	
	private void triggerABS() {
		... implementation to engage the ABS system ...
	}
	
}

Listing 4

public class Automobile {
	... other variables ...
	
	private int rpms;

	... other methods ...

	public int getRPMs() {
		return rpms;
	}

	private void setRPMs(int rpms) {
		this.rpms = rpms;
	}
}

Listing 5

	public class Automobile implements Fuelable
	{
		... other methods
		public void refuel(double amount)
		{
			... some implementation
		}
}
 
	public class Truck implements Fuelable
	{
		... other methods
		public void refuel(double amount)
		{
			... some implementation
		}
}

 

All Rights Reserved
Copyright ©  2004 SYS-CON Media, Inc.
  E-mail: [email protected]

Java and Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. SYS-CON Publications, Inc. is independent of Sun Microsystems, Inc.