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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With