CS 580 Client-Server Programming Fall Semester, 2000 Hinges |
||
---|---|---|
© 2000, All Rights Reserved, SDSU & Roger Whitney San Diego State University -- This page last updated 30-Aug-00 |
Hinges
Software is not arbitrarily adaptable
One can not modify existing software arbitrarily
Can add places designed to change
These spots can be though of as hinges or hot spots
Changes at one of these hinges is relatively easy
Changing software in other locations or ways tends to:
Force
Hinge Example - Constants
Program that uses course numbers
class Example extends Frame { public Example() { setTitle( "Hinge Example" ); resize( 100, 100 ); setLayout( new FlowLayout() ); add( new Button( "CS 596") ); show(); } public boolean action( Event processNow, Object buttonPressed ) { if ( buttonPressed.equals( "CS 596" ) ) System.out.println("Pressed"); return true; } }
First Hinge
class Example extends Frame { String courseName = "CS 596"; public Example() { setTitle( "Hinge Example" ); resize( 100, 100 ); setLayout( new FlowLayout() ); add( new Button( courseName ) ); show(); } public boolean action( Event processNow, Object buttonPressed ) { if ( buttonPressed.equals( courseName ) ) System.out.println("Pressed"); return true; } }
Another Hinge
class Example extends Frame { String courseName; public Example() { try { ASCIIInputStream cin = new ASCIIInputStream( new BufferedInputStream ( new FileInputStream( "ExampleConfig" )) ); courseName = cin.readWord() + cin.readWord(); setTitle( "Hinge Example" ); resize( 100, 100 ); setLayout( new FlowLayout() ); add( new Button( courseName ) ); show(); } catch ( FileNotFoundException noFile ) { System.out.println( "No Config file"); } catch ( IOException readError ) { System.out.println( "Read Error"); } } public boolean action( Event processNow, Object buttonPressed ) //Same as before }
ExampleConfig Contents
CS 569
This is a Hinge?
How safe?
How extendable?
Some Hinge Oil
sdsu.util.ProgramProperties
Parses
Simple Example
import sdsu.util.ProgramProperties; public class ConfigurationExample { public static void main(String args[]) { try { ProgramProperties flags = new ProgramProperties( args, "configurationFile"); String nameValue = flags.getString( "name" , "No name given"); int size = flags.getInt( "size", 0); boolean switchOn = flags.containsKey( "s"); System.out.println( " nameValue: " + nameValue); System.out.println( " size: " + size); System.out.println( " switchOn: " + switchOn); } catch (java.io.IOException readParseProblem) { System.err.println( "Program aborted on error " + readParseProblem); } } }
File "configurationFile.labeledData" name=Roger; size=12;
Sample Runs
java ConfigurationExample
Output nameValue: Roger
size: 12
switchOn: false
java ConfigurationExample -s -name Pete
Output nameValue: Pete
size: 12
switchOn: true
java ConfigurationExample -conf=otherFile
Output nameValue: Sam
size: 8
switchOn: true
Copyright ©, All rights reserved.
2000 SDSU & Roger Whitney, 5500 Campanile Drive, San Diego, CA 92182-7700 USA.
OpenContent license defines the copyright on this document.
Previous    visitors since 30-Aug-00    Next