• Post Reply Bookmark Topic Watch Topic
  • New Topic

Question about accessing /restriction on public objects  RSS feed

 
Santosh Maskar
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have 4 differnt java applications

Client ----- Engine ------ Java Classes ------ Server

In "Java classes" module I have the two public classess public class A and public class B

my client can access class A throuhg engine but at the same time I dont want to give the access of public clas B to the client. in this case I could think making class B as private/protected but I can not do this because In my server module I need object of Class B thats the root cause of making these classes public

I am thinkning about the following solutions
1. add the key in these clasess and give the access to these classes depending upon the key thay client is passing - but it requried lots of code changes

is there any best solution for this problem



Thanks,
Santosh ( )
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instead of exposing the complete Object B to the client, who don't you create an interface which encapsulates just those methods the client should see?
 
Santosh Maskar
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ulf Dittmer:
Instead of exposing the complete Object B to the client, who don't you create an interface which encapsulates just those methods the client should see?


Because I need the same object in my Server module.

I found one solution for this problme but I am not happy with this


Customize scoping with object keys
[ December 22, 2005: Message edited by: Santosh Maskar ]
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you give the necessary visibility by adjusting packages and classpath setting?
 
Santosh Maskar
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My question is like I already explained.

How can I restric the access of public class for one application and at the same time I need these public classes in my other application.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because I need the same object in my Server module.

Yes, you would use the object in the Server app, but you would define the client API so that it only deals in terms of the interface (which the object implements), not in terms of the object itself.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can introduce a layer of public objects that hides a layer of private objects.

This doesn't prevent a Client coder from using the ServerAPI unless you can somehow avoid distributing the ServerAPI class to the client team.

It's a little odd to have both client and server depending on JavaClasses. It might be a global framework, a case of really cool Dependency Inversion or a case of circular dependencies. Why does that happen?
[ December 22, 2005: Message edited by: Stan James ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!