![]() |
CS 535 Object-Oriented Programming & Design Fall Semester, 2000 Some Code Comments |
|
---|---|---|
© 2000, All Rights Reserved, SDSU & Roger Whitney San Diego State University -- This page last updated 17-Sep-00 |
public BooleanQuestion(String message, String methodName1, String methodName2, Object objectName1, Object objectName2 ) public BooleanQuestion(String message, String trueCallbackMethod, Object trueReceiver, String falseCallbackMethod, Object falseReceiver)
public class p1 { blah }
pubic class Question { public String stringQuestion( String message ) { System.out.println( "message" ); System.out.println( "Your answer: " ); String response = Console.readLine().trim(); return response; } public boolean booleanQuestion( String message ) { try { System.out.println( "message" ); System.out.println( "Your answer: " ); booelan response = Console.readBoolean(); Console.flushLine(); return response; } catch (NumberFormatError badInput ) { //blah} } public int intQuestion( String message ) { try { //blah } catch (NumberFormatError badInput ) {//more blah } } }What is the abstraction? Where is the data?
public class BooleanQuestion extends ASCIIComponent { private static String[] trueAnswers = { "true", "t", "yes", "y" }; private static String[] falseAnswers = { "false", "f", "no", "n" }; private String text; private CallBackAdapter trueCallBack; private CallBackAdapter falseCallBack;
public class foo { int data; int value; public setData() { value = sdsu.io.Console.readInt( "Type an int for data" ); } public void setValue(int aValue) { value = aValue; }Contrast the two methods. The setData method uses Console, which uses System.out and System.in. The method is now coupled to those classes. It has to be used with a text based user interface. It also assumes that the user always enters the value for data. What happens if the value is computed? The setValue method is not coupled to the Screen. Other code will obtain the value and pass it to setValue. So the value can be obtained by asking user (via text based or graphical based interface), from a file, computed from other data, etc.
public void method1() { int foo = 12; //blah statement1; statement2; statement3; // more blah } public void method2() { int bar = 42; //stuff statement1; statement2; statement3; // more stuff }
public void method1() { int foo = 12; //blah foo = repeated( whatGoesHere ); // more blah } public void method2() { int bar = 42; //stuff bar = repeated( something ); // more stuff } public int repeated(Object agrument) { statement1; statement2; statement3; return result; }