I am stuck with college coursework - at least i admit it :)

T

thespid

I have completed the first part of my coursework and the second part
of my coursework requirement is as follows :-

"To reduce the risk of introducing bugs, you are not allowed to make
changes to existing classes. In addition it should be possible to
deploy the application with or without testing code in place. In
either case the application code should be unchanged."

I have made main either call LibraryFrame or DebugLibraryFrame by
parameter "debug" being passed in. DebugLibraryFrame is created as an
abstract factory to create a DebugLibrary class and this then
instantiates concrete classes through the same interfaces a
LibraryFrame would have. I could go ahead and create a whole Debug*
class structure but this seems to defeat the purpose of the exercise.

I guess I need to decorate the 3 classes which are asked for, but how
can I decorate them without making changes to existing classes?
 
C

Chris Smith

thespid said:
I have completed the first part of my coursework and the second part
of my coursework requirement is as follows :-

"To reduce the risk of introducing bugs, you are not allowed to make
changes to existing classes. In addition it should be possible to
deploy the application with or without testing code in place. In
either case the application code should be unchanged."

I have made main either call LibraryFrame or DebugLibraryFrame by
parameter "debug" being passed in. DebugLibraryFrame is created as an
abstract factory to create a DebugLibrary class and this then
instantiates concrete classes through the same interfaces a
LibraryFrame would have. I could go ahead and create a whole Debug*
class structure but this seems to defeat the purpose of the exercise.

I guess I need to decorate the 3 classes which are asked for, but how
can I decorate them without making changes to existing classes?

Can you provide more information? Without seeing the code, or for that
matter even knowing which code is provided and which is not, there's no
way anyone can help much.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
A

Andrew Thompson

thespid said:
I have completed the first part of my coursework and the second part
of my coursework requirement is as follows :-

"To reduce the risk of introducing bugs, you are not allowed to make
changes to existing classes. In addition it should be possible to
deploy the application with or without testing code in place. In
either case the application code should be unchanged."

I ask as someone who has not used them,
but do assertions achieve what you want?
http://java.sun.com/j2se/1.4.1/docs/guide/lang/assert.html

Not too sure about 'not making changes
to exisiting classes' bit though..
 
T

thespid

I cant post all of the code as it would fill many many pages. I have
completed part 1 so the code provided has changed a lot, however I
have the following setup.
One of the classes I have to add testing code to without changing is
BorrowerRecordImp which is in the loansubsystem package. If I could
understand how to do that then I will be able to carry on with the
rest myself.

Main.java:
public static void main(String[] args) {

if ( args.length == 0 ) {
LibraryFrame frame =
LibraryFrameMaker.makeLibraryFrame("standard");
} else if ( args[0].equals("debug") ) {
LibraryFrame frame =
LibraryFrameMaker.makeLibraryFrame("debug");
} else {
System.out.println("\nUsage: Main |optional parameters|
<debug>");
}

} // method: main

LibraryFrameMaker:
import librarysubsystem.*;

public class LibraryFrameMaker
{
private LibraryFrameMaker() {}

public static LibraryFrame makeLibraryFrame(String libraryType)

** do the business here

librarysubsystem/LibraryFrame:
package librarysubsystem;
public class LibraryFrame extends javax.swing.JFrame {

librarysubsystem/DebugLibraryFrame:
package librarysubsystem;
public class DebugLibraryFrame extends LibraryFrame {

loansubsystem/BorrowerRecordIF:
package loansubsystem;
public interface BorrowerRecordIF {

loansubsystem/BorrowerRecordImp:
package loansubsystem;
public abstract class BorrowerRecordImp extends
java.util.Observable implements java.lang.Comparable,
java.io.Serializable, BorrowerRecordIF {

Thanks in advance for any help given.
 
A

Anthony Borla

thespid said:
I have completed the first part of my coursework and the
second part of my coursework requirement is as follows :-

"To reduce the risk of introducing bugs, you are not allowed
to make changes to existing classes. In addition it should be
possible to deploy the application with or without testing code
in place. In either case the application code should be
unchanged."

I interpret this to mean you cannot alter existing application class source
code. It doesn't appear to prohibit sub-classing, though this depends on
what the phrase:

" ... the application code should be unchanged."

actually means. Besides, this may not be what your instructors want you to
do.
I have made main either call LibraryFrame or DebugLibraryFrame
by parameter "debug" being passed in. DebugLibraryFrame
is created as an abstract factory to create a DebugLibrary class
and this then instantiates concrete classes through the same
interfaces a LibraryFrame would have. I could go ahead and
create a whole Debug* class structure but this seems to
defeat the purpose of the exercise.

Sounds like a reasonable approach, though cannot say for sure without
knowing more assignment requirement specifics.
I guess I need to decorate the 3 classes which are asked
for, but how can I decorate them without making changes
to existing classes?

Without knowing what the assignment requirement specifics are, it is
difficult to make suggestions. General comments [actually, just 'stabs in
the dark' ;)]:

* You can't decorate unless the supplied classes are designed
to be 'decoratable' i.e. contain a field reference to the base
class

* You could sub-class if this is permissable - maybe alter
the internals of your Factory to instantiate these new
objects ?

* You could wrap existing class object(s) using Facade, or
use them as the implementation part in a Bridge ?

Much of this advice hinges on what the phrase:

" ... the application code should be unchanged."

actually means.

I hope this helps.

Anthony Borla
 
X

xarax

thespid said:
I have completed the first part of my coursework

What was the first part?
and the second part
of my coursework requirement is as follows :-

"To reduce the risk of introducing bugs, you are not allowed to make
changes to existing classes. In addition it should be possible to
deploy the application with or without testing code in place. In
either case the application code should be unchanged."

This sounds very much like sub-classing and using interfaces.
I have made main either call LibraryFrame or DebugLibraryFrame by
parameter "debug" being passed in. DebugLibraryFrame is created as an
abstract factory to create a DebugLibrary class and this then
instantiates concrete classes through the same interfaces a
LibraryFrame would have. I could go ahead and create a whole Debug*
class structure but this seems to defeat the purpose of the exercise.

An alternative is to use a Properties file that a factory
object will inspect to determine what class(es) to instantiate.
I guess I need to decorate the 3 classes which are asked for, but how
can I decorate them without making changes to existing classes?

Sub-classes.

--
----------------------------------------------
Jeffrey D. Smith
Farsight Systems Corporation
24 BURLINGTON DRIVE
LONGMONT, CO 80501-6906
http://www.farsight-systems.com
z/Debug debugs your Systems/C programs running on IBM z/OS!
 
A

Anthony Borla

thespid said:
I cant post all of the code as it would fill many many pages.
I have completed part 1 so the code provided has changed
a lot, however I have the following setup.

One of the classes I have to add testing code to without
changing is BorrowerRecordImp which is in the
loansubsystem package. If I could understand how to do
that then I will be able to carry on with the rest myself.

Main.java:
public static void main(String[] args) {

if ( args.length == 0 ) {
LibraryFrame frame =
LibraryFrameMaker.makeLibraryFrame("standard");
} else if ( args[0].equals("debug") ) {
LibraryFrame frame =
LibraryFrameMaker.makeLibraryFrame("debug");
} else {
System.out.println("\nUsage: Main |optional parameters|
<debug>");
}

} // method: main

LibraryFrameMaker:
import librarysubsystem.*;

public class LibraryFrameMaker
{
private LibraryFrameMaker() {}

public static LibraryFrame makeLibraryFrame(String libraryType)

** do the business here

librarysubsystem/LibraryFrame:
package librarysubsystem;
public class LibraryFrame extends javax.swing.JFrame {

librarysubsystem/DebugLibraryFrame:
package librarysubsystem;
public class DebugLibraryFrame extends LibraryFrame {

loansubsystem/BorrowerRecordIF:
package loansubsystem;
public interface BorrowerRecordIF {

loansubsystem/BorrowerRecordImp:
package loansubsystem;
public abstract class BorrowerRecordImp extends
java.util.Observable implements java.lang.Comparable,
java.io.Serializable, BorrowerRecordIF {

// (1) Probably what is required - sub-class the implementation
class MyBorrowerRecordImp extends BorrowerRecordImp
{
...
...
}

// Choose whichever is appropriate ...
BorrowerRecordImp bri = new MyBorrowerRecordImp();
// or:
BorrowerRecordIF bri = new MyBorrowerRecordImp();
// or:
// Make inside some Factory ...
// ...

// (2) Wrapper Approach [Not applicable, shown for completeness
// as possible approach to this type of problem]
class MyBorrowerRecordWrapper implements BorrowerRecordIF
{
...
void method1() { bri_.method1(); }
...
int method2() { return bri_.method2(); }
...
private BorrowerRecordImp bri_ = new MyBorrowerRecordImp();
}

BorrowerRecordIF bri = new MyBorrowerRecordWrapper();

I hope this helps.

Anthony Borla
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top