I'd want a method to be called only by objects of a specific class

Posted by mp on Stack Overflow See other posts from Stack Overflow or by mp
Published on 2010-06-02T16:18:42Z Indexed on 2010/06/02 16:24 UTC
Read the original article Hit count: 178

Filed under:
|
|

Suppose you have this class:

public class A
{
    private int number;
    public setNumber(int n){
        number = n;
    }
}

I'd like the method setNumber could be called only by objects of a specific class. Does it make sense? I know it is not possible, is it? Which are the design alternatives? Some well known design pattern? Sorry for the silly question, but I'm a bit rusty in OO design.

© Stack Overflow or respective owner

Related posts about design

Related posts about Patterns