The Law of Demeter also known as the principle of least knowledge is a coding principle, which says that a module should not know about the inner details of the objects it manipulates. If a code depends upon the internal details of a particular object, there is a good chance that it will break as soon as the internal of that object changes. Since Encapsulation is all about hiding internal details of an object and exposing only operations, it also asserts the Law of Demeter. One mistake many Java programmer makes it exposing internal detail of object using getter methods and this is where the principle of least knowledge alerts you.
Monday, July 7, 2025
Wednesday, June 4, 2025
Top 23 Design Patterns Experienced Java Programmers Should Learn
Hello guys, if you want to learn Design Patterns and looking for a comprehensive tutorial which covers all important object oriented design pattern then you have come to the right place. Earlier, I have shared best Design pattern courses and books for experienced developers and in this article, I will introduce you with 23 common object oriented design patterns for writing better code. Design Patterns are tried and tested way of solving a problem within a given context. They are not invented, rather they are discovered, which is also obvious by use of word pattern. By using design pattern, you take knowledge of all wide communities and can safely use it to solve that problem. At times they might not give you perfect solution, require bit of tweaking, but they certainly provides one of the best solution, as long as you use them properly. While doing object oriented development, they are numerous task which appears quite often e.g. creating objects, structuring code, and implementing different behaviors based on different context.
Monday, May 5, 2025
How to Design Vending Machine in Java - Part 2 [Object Oriented Design Problem with Solution]
This is the second part of the Java tutorial to show how to design Vending Machine in Java. In the first part, we have discussed the problem statement and the solution itself, but unit testing and design document were still pending, which we'll see in this article. As I said, there are multiple ways to design a Vending machine in Java, for example, you could have easily used state design patterns to implement a vending machine, in fact, it's one of the best examples of State design patterns. Vending machine behaves differently in different states like return a product if the machine is not empty, otherwise, it just returns coins, so it ideally fits in the state design pattern.
Subscribe to:
Posts
(
Atom
)