Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java design pattern

I am new to design pattern. I have a small project in which java classes use dummy data when not connected to server. I have if condition in class that switches between dummy data and server data depending on a flag . Is there a better way this can be implemented?

like image 846
Paneri Avatar asked Jun 20 '26 20:06

Paneri


1 Answers

Instead of controlling your code with an 'if' statement, you should write an interface that defines all the methods you will need to interact with the server, and reference that interface instead of a concrete implementation. Then, have your 'dummy data' implement that interface.

The advantage of this is that your code will be written in a way that is not dependent upon the server implementation. This will allow you to change details on the server without changing your client's implementation.

like image 110
mtmurdock Avatar answered Jun 22 '26 09:06

mtmurdock



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!