aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Constructor of the Data.java class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Constructor of the Data.java class" Watch "Constructor of the Data.java class" New topic
Author

Constructor of the Data.java class

Heri Bender
Greenhorn

Joined: Jan 07, 2011
Posts: 16
Hi all

I am unsure about the required constructor for the implementation of the given interface. The assignment says nothing about it. Is it allowed to declare a constructor with parameters?

How can the my assignment then be automatically examinated by software if it cannot construct the instance?

Tks for reply

Heri
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5596
    
  15

If there is no "must" requirement about the constructor you are free to do what you want In fact I applied the singleton design pattern on my Data class, so my default constructor is marked private and i passed

Maybe they have for automatic testing a program where they just have to add 1 line: creating the Data instance (according to your javadoc) and let it run...


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Andy Gertjejansen
Greenhorn

Joined: Dec 30, 2010
Posts: 16

Hey Roel,
I am using a singleton as well. I pass in a database path into getInstance method and actually have an overloaded version without params. I know this is a terrible design but I throw a custom exception when it isn't used properly. Is there a way I didn't think of to get around this. I don't like the idea of having a setter for the database path. How did you get the database path to Data? by the way I have been reading a lot of your posts... You are a very adept at teaching, when you help people solve their problems you do it in a way that is understandable and you are very humble (in my opinion a must for any teacher) which helps people build their confidence. I was very insecure when I began the project, only a week later, I am almost cocky! Just wanted to say thanks man .


A+ 2009, OCPJP 6, (Working on: OCMJD 6)
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5596
    
  15

Hi Andy,

My Data class has just 1 getInstance method with 0 parameters, so you can get around this (and I didn't use a setter too). What did I do? I created my own interface which extends the given interface and I added 2 methods to this new interface: 1 for initializing (with a parameter containing the database path) and another one for "destroying" (releasing any resources, writing cache back to file,...)

Andy Gertjejansen wrote:I have been reading a lot of your posts... You are a very adept at teaching, when you help people solve their problems you do it in a way that is understandable and you are very humble (in my opinion a must for any teacher) which helps people build their confidence. I was very insecure when I began the project, only a week later, I am almost cocky!

Thanks for these kind words, Andy. Some appreciation now and then is always nice to hear Concerning the teaching: before I started my Applied Computer Sciences study, I was trying to become a secondary teacher, because being a math teacher was my little boy's dream. After 1.5 years I decided it wasn't my cup of tea and switched to the IT training, a very wise decision in the end

Kind regards,
Roel
Andy Gertjejansen
Greenhorn

Joined: Dec 30, 2010
Posts: 16

I suppose...I remember saying you had a custom interface. I get it, that way you can just cache the data and the other methods just deal with a Map. Thanks again sir!
Thanks,
Andy
Andy Gertjejansen
Greenhorn

Joined: Dec 30, 2010
Posts: 16

Sorry for bothering you so much just to make sure. You had an interface (lets call it Foo) that extends the DB interface and then just implemented Foo and that was ok with the assessors? I imagine it would be because you are still implementing DB by implementing an interface that extends to it but just thought I would ask to make sure. I also don't mean to straight up copy your design but it is such a good idea unfortunately I cannot resist!
Thanks again,
Andy
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5596
    
  15

Hi Andy,

Not a problem

Did you already have read my story about SCJD? A link is provided in my signature. It contains a lot of information about how I tackled/handled the assignment and also an overview of the high-level decisions I took. First item under "Data class" is:
Roel De Nijs wrote:created my own interface (extending the sun interface)

And as you can see I passed (even with a maximum score ), so it's certainly fine for the accessors.

Kind regards,
Roel
Andy Gertjejansen
Greenhorn

Joined: Dec 30, 2010
Posts: 16

Thanks Roel!! I thought that's what you did but I was a little nervous thought I would double check. Wow perfect score very impressive!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Constructor of the Data.java class