aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Testing of data class instance(s) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Testing of data class instance(s)" Watch "Testing of data class instance(s)" New topic
Author

Testing of data class instance(s)

Mattew Force
Greenhorn

Joined: May 03, 2007
Posts: 16
Hi,

In order for the examiners to test the data class they should be able to get an instance of it in a way that it documented, right? After reading the instructions carefully, I assume there's no need of a default constructor.

The issue I'm having is that I have a database class which has the data class as a variable (no setters or getters though, it's a kind of delegate) and it passes itself (during instantiation) to the data class as a parameter so that the data class knows how it should read/write data since the database class knows the schema etc.

There is a way to test the data class separately, but it requires to also create an instance of the database class (which has the schema, remember)and thus we will end up with two instances of the data class (one which the tester has an instance of and one which is in the database class).

If the examiners only test the methods through the data instance they get directly and not indirectly (delegation) through the database instance, I should be ok. However, if they test the two instances of the data class with different threads, I don't know how things will work. The data class uses an instance of RandomAccessFile to read/write the data file. Is this a bad design?

I don't want the database class to expose the data class via getters. Can anyone give me a hint on how I should continue? It seems to me that I'm running in circles.

Regards,

Mattew
Jason Moors
Ranch Hand

Joined: Dec 04, 2001
Posts: 188
Hi Mattew,

Why are you creating the schema in your Database class? In my application the schema is read from the header section of the db file in the Data class using RandomAccessFile.

Regards
Jason
Mattew Force
Greenhorn

Joined: May 03, 2007
Posts: 16
Originally posted by Jason Moors:

Why are you creating the schema in your Database class? In my application the schema is read from the header section of the db file in the Data class using RandomAccessFile.


Well, I think the schema should belong in the database class so it is possible to create a flexible gui which is based on the constraints of it. Also, I'm not allowed to add a getSchema method in the data class because then I would break the DB interface :-/

Regards,

Mattew
Jason Moors
Ranch Hand

Joined: Dec 04, 2001
Posts: 188
Have a look at this post it may help.

Extend the DBMain Interface

Jason
Mattew Force
Greenhorn

Joined: May 03, 2007
Posts: 16
Originally posted by Jason Moors:
Have a look at this post it may help.

Extend the DBMain Interface

Jason


Thanks Jason, I have the schema and the records stored in the data class now since it seems perfectly valid to extend the DB interface.

Regards,

Mattew
uzma ali
Ranch Hand

Joined: Jun 22, 2007
Posts: 56
I read through all the posts and links given in this topic and came up with a question.

1) whether extending the DB interface will be a good idea or
2) DBmain class implement multiple interfaces

I think in the second case integrity of DB interface will also stay the same while we can have other methods in the implemented class which it can take/implement from the second interface.

Please advise
Uzma
Jason Moors
Ranch Hand

Joined: Dec 04, 2001
Posts: 188
Hi Uzma,

I'm not sure that the Data class implementing two interfaces will work, how would you access the methods in both interfaces. i.e.



If you want to provide additional functionality I would recommend that you extend the DBMain interface and then implement the extended interface in your Data class.

Regards
Jason
uzma ali
Ranch Hand

Joined: Jun 22, 2007
Posts: 56
Thanks Jason

Now I have two more questions:
1) What is the benefit other than developing on cocrete class(if it is really a benefit)in case of a) over b):
a)DBMain data = new Data();
b)Data data = new Data();

My second question is which I have a bit idea from your reply:
If we can define more methods in the data class then why is the need to extend it and declare other methods in the second interface . The answer again is ,I think, developing on interface not on concrete class.

Please explain I might be lacking in some of my concepts.

Thanks again

Uzma
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Testing of data class instance(s)