Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Object hierarchical call in JAVA

I have a question regarding the Object hierarchical call.

I have four classes namely A, B, C, D.

D will be set in C; C will be in B; B will be in A.

If I want to do something in class D, I have to call a.b.c.d.setWidth("50%");(a, b, c, d are instance of Class A, B, C, d).

Is that fine to call like that? Will that compromise the performance?

like image 881
Gugan Avatar asked Dec 04 '13 05:12

Gugan


1 Answers

The effect on performance will be very slight... the bigger issue is what that does to your object-oriented model.

Having direct access to the members of a class is frowned apon, and you are running risks of NullPointerExceptions.

What you should be more worried about is the readability and maintainability of your code.

like image 158
rolfl Avatar answered Oct 04 '22 19:10

rolfl