|
| |
"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: info@sys-con.com
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.
|