Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

access levels in code from sun

 
Suchak Jani
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Team,
This might be a very stupid question, still i guess i will ask it.
The access levels in the code given by Sun for the assignment , could be more restrictive . I have not yet started coding the assignment as i am still designing and hence the question.
Am i allowed to change their access levels, for eample from "public" to "private", etc.
Thanks in advance!
Regards
Suchak Jani
(After reading here for a couple of days, I find this group very helpfull and noble in intent)
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can do anything you want to their code. But you will need to defend yourself in the design.txt file and in the essay exam. I don't think you will need to change them anyway. They are what the really should be.
Mark
 
Suchak Jani
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark,
Thanks for your reply.
I just wanted to give an example. The database class(not wanting to name it) given by them is public. Now that means that any one can create instances.
It is best to have only one instance of this database class i suppose. I would think that some form of Singleton access would be meaningfull here.
So would it not make sense to make it at least protected?
Regards
Suchak Jani
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You know I remember there being posts about having the Data class be a Singleton. But I still haven't found out where this is neccessary. If you want to do that, I suggest doing a query here on Singleton, and see what they say. they might have a good reason why you need it or not.
Hope that leads you in the right direction.
Mark
 
Steve Granton
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Presumably you are suggesting that the Singleton pattern would be used to guard access to the data file by ensuring that all clients use the same instance for access? I've also thought about this as multiple instances of the Data class with synchronised methods would not ensure exclusive access to a file.
You could use a singlton lock manager class that each Data class would use to obtain exclusive access. However, if you were using multiple data files then this could stop concurrent access to different files - thus slowing the application. Really what you want is a pattern that only allows once instance of a class to be instantiated for each data file that is being used. This could be done - though I expect it is beyond the scope of this assignment.
I think I'm going to use the single instance of the server bound to the RMI registry to instantiate the only data class. Thus all clients would access the data file through the same Data class. I know this is not ideal as this only works where clients access the file through the object bound to the RMI.
Maybe Mark (or others) can comment on whether there is a problem with my solution. And whether this is sufficient to pass the assignment.
Thanks,
Steve
 
Suchak Jani
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
>So would it not make sense to make it at least >protected?
I meant
"So would it not make sense to make it at least 'default'?"
Rergards
Suchak Jani
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I'm going to use the single instance of the server bound to the RMI registry to instantiate the only data class. Thus all clients would access the data file through the same Data class. I know this is not ideal as this only works where clients access the file through the object bound to the RMI.

You are close. The object bound in RMI is the only class that instantiates an instance of the Data class in remote mode. However, you can also have a method in that object called getConnection() which returns a remote object of the DataAccessRemote class that implements the DataAccess interface. This class has a constructor that takes a Data class parameter, which is the one inside the RMI bound object, hence each remote object has a reference to the one and only one instance of the Data class.
And in local mode you don't have to worry about that since the client is the only one that creates the instance of the Data class for its own use.
Mark
 
Hima Arimanda
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark , thanx for the responses. Iam stuck with something. I have a serverimpl which is the one bound to the registry and it is the one instantiating the Data class, implemented as a singleton. Now i have a get method in this object which returns the instance of the data object. With the help of the interface, my client is able to get the reference to the Data class. But when i use the mehtods on this data object reference at client, like getFieldInfo(), i get null.Am i doing somethig wrong?
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm. Tough to answer from just that. But my guess would lie in how the Data class object gets returned to the client.
Here are my questions.
Did you change all the classes to be Serializable? That is my guess based on what you wrote. You are trying to send the object down to the client, rather than sending a reference to the client, and having the object actually reside on the server instead.
If you extend Remote, you make the object a remote object, and only a reference of the object gets sent to the client.
Hope that helps, again it is tough to answer on little info
Have you tried to put System.out.println() codes in your Data class to see how far the code is getting when the client makes a call to the Data class. That was my great way of debugging
Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic