• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Constructor of the Data.java class

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Greenhorn
Posts: 16
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 .
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 16
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 16
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 16
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
reply
    Bookmark Topic Watch Topic
  • New Topic