aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes An abstract Data class 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 "An abstract Data class" Watch "An abstract Data class" New topic
Author

An abstract Data class

Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5266
    
  13

Hi all,

when i'm writing my choices.txt I was wondering about the Data class: is it allowed to be abstract? or should it be a concrete class? instructions don't tell anything about it and for the record: data would implement all methods from sun's interface.

Regards,
Roel


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Fernando Franzini
Ranch Hand

Joined: Jan 09, 2009
Posts: 486
    
    2

HI

In my assignament was especifield "Your data acess must be called....." for me it's mean concrete class !!!
Let's wait another rancherss
Regardssss


Fernando Franzini - Java Blog
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2409
    
    7

Concrete class man cos you need to implement those interface (Sun provide or your own). Eventually if you use a service layer you can delegate those search, create etc methods to the Data class.


K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7 OCPWCD5
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5266
    
  13

Hi K. Tsang,

I noticed you past the scjd assignment, congrats

Of course i would have the abstract data class, and a concrete RoomData class for example. and i would use the RoomData class to delegate my service methods to. But if at sun they try to create an instance of Data, it would fail because it's abstract.

But you had a singleton Data, so your constructor of Data should be marked private and so they cannot create an instance of your Data class, so it seems it may be an abstract class. but i won't change it now anymore, to close to the finish line

Kind regards,
Roel
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2409
    
    7

abstract class and singleton class are 2 different things I think. Singleton must have a getInstance() method meaning you can create it or have an instance of it. Abstract class you can't even have an instance.

So what methods you have in your Data class if you also have a RoomData concrete class. If RoomData simply overrides Data class methods.... I don't see you need the extra RoomData class.
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5266
    
  13

Hi K. Tsang,

I was a bit unclear in my explanation. I meant if a program is used to test automatically your program and program contains coding like this

This program will not compile when Data is abstract class, but also not compile when you have a singleton, because Data.getInstance() should be invoked to get an instance.

The reason why i would make my data abstract and have a concrete RoomData has to do with making the Data a generic data access class which could be used to handle a file with rooms (through the RoomData, which has a speific check for eg. magic cookie and in future maybe also some other specific implementations of Data methods), but could also handle easily a file with customers (through a new concrete CustomerData class extending from Data). So it would become very easy to handle a similar file as the database file with hotel rooms

Kind regards,
Roel
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2409
    
    7

Hi Roel, I see your point why you want to make Data class abstract. In that case go for it, just mention it in your choices.txt document.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: An abstract Data class