this is more theoretical question. I have written simple chat with my friend. We have few classes, but most important are Client (handles network stuff) and GUI (self-explanatory :)).
Now, I write messages into JTextArea. And I want to ask, from the OOP theory, is it better to send to Client reference to JTextArea and directly append text to it, OR is better to create function in GUI which makes the same and call it from Client? When message comes from server of course.
I know the most efficient way is the first, but I believe its not the proper OOP way. I have found that OOP is less efficient than procedural, not becouse its more complex on abstraction, but becouse many OOP standarts just seems ineficient. Thanks.
You should encapsulate the functionality of the GUI. The client shouldn’t have any knowledge of its inner workings whatsoever. Instead, you should provide a semantically meaningful public method that describes the task it will perform – in this case updating the display.
Ideally you should have an interface that represents your GUI actions also – this will decouple the client from the GUI and will mean you can have multiple UIs implement the interface and the client doesn’t care which UI it is using.