Skip to main content
added 17 characters in body
Source Link
Mike Nakis
  • 32.8k
  • 7
  • 82
  • 116

From both an academic and a technical point of view, it is not okay.

From an academic point of view, you are violating the principle of encapsulation.

From a technical point of view, if you need to do any further refactoring in the future, you will have a lot of work to do.

That having been said, there is also a practical point of view, which boils down to this: if your IDE gives you the ability to refactor ab from public to private, adding all necessary accessors and replacing all references to root.ab with invocations of these accessors all over your entire code base, and if it can do that with just a couple of clicks and keystrokes, you are fine. If not, you are better off not doing it.

It is not clear to me what you mean by sub-object c, but if you mean a subclass, then consider making ab protected. This way, c will be able to access it, but no outside code will.It is not clear to me what you mean by sub-object c, but if you mean a subclass, then consider making ab protected. This way, c will be able to access it, but no outside code will.

From both an academic and a technical point of view, it is not okay.

From an academic point of view, you are violating the principle of encapsulation.

From a technical point of view, if you need to do any further refactoring in the future, you will have a lot of work to do.

That having been said, there is also a practical point of view, which boils down to this: if your IDE gives you the ability to refactor ab from public to private, adding all necessary accessors and replacing all references to root.ab with invocations of these accessors all over your entire code base, and if it can do that with just a couple of clicks and keystrokes, you are fine. If not, you are better off not doing it.

It is not clear to me what you mean by sub-object c, but if you mean a subclass, then consider making ab protected. This way, c will be able to access it, but no outside code will.

From both an academic and a technical point of view, it is not okay.

From an academic point of view, you are violating the principle of encapsulation.

From a technical point of view, if you need to do any further refactoring in the future, you will have a lot of work to do.

That having been said, there is also a practical point of view, which boils down to this: if your IDE gives you the ability to refactor ab from public to private, adding all necessary accessors and replacing all references to root.ab with invocations of these accessors all over your entire code base, and if it can do that with just a couple of clicks and keystrokes, you are fine. If not, you are better off not doing it.

It is not clear to me what you mean by sub-object c, but if you mean a subclass, then consider making ab protected. This way, c will be able to access it, but no outside code will.

Source Link
Mike Nakis
  • 32.8k
  • 7
  • 82
  • 116

From both an academic and a technical point of view, it is not okay.

From an academic point of view, you are violating the principle of encapsulation.

From a technical point of view, if you need to do any further refactoring in the future, you will have a lot of work to do.

That having been said, there is also a practical point of view, which boils down to this: if your IDE gives you the ability to refactor ab from public to private, adding all necessary accessors and replacing all references to root.ab with invocations of these accessors all over your entire code base, and if it can do that with just a couple of clicks and keystrokes, you are fine. If not, you are better off not doing it.

It is not clear to me what you mean by sub-object c, but if you mean a subclass, then consider making ab protected. This way, c will be able to access it, but no outside code will.