Solved

how to restrict calling methods in different classes

Posted on 2007-04-02
7
307 Views
Last Modified: 2010-03-31
i have a class c1 defined f1(),f2() and f3() methods;in c2 class there i have to access f1() method only and c3 class i have to access only f2 and f3 methods;how to restrcit this?
0
Comment
Question by:chaitu chaitu
7 Comments
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
ID: 18835142
u can't really.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 18835169
Install a security manager
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 18835175
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 8

Expert Comment

by:mhunts
ID: 18835183
Why don't you split c1 into 2 classes, one with f1, and one with f2, f3. Then c2 can access the first one, and c3 can access the second one.
0
 
LVL 4

Expert Comment

by:jcoombes
ID: 18835295
Another approach here would be to utilise AOP techniques to inject advice and pointcuts that restrict the calling of the necessary methods, based on the type of the calling class.

There's a whole bunch of literature available out there that explains the basic concepts of AOP, here's probably a good jump off point:

http://en.wikipedia.org/wiki/Aspect-oriented_programming
0
 
LVL 11

Expert Comment

by:elfe69
ID: 18835430
Is it really necessary to hide those methods to the other classes ?
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 18839212
When you define something as public, default, etc you dont do it for a specific outside class - you define it as public for all other classes to access, etc
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question