Observability Done Right: Best Practices and Anti-Patterns for Effective System Monitoring

Image
  WHAT Observability is a concept that refers to the ability to gain insights into the behavior and performance of complex systems. In the context of software engineering, observability involves the collection, analysis, and visualization of data from software applications, infrastructure, and other components of a system. In the animal kingdom, observability plays a critical role in survival, allowing animals to monitor their surroundings, detect threats, and find food. Dolphins use echolocation to observe their surroundings. They emit high-frequency sounds that bounce off objects, allowing them to create a 3D map of their environment. Thanks for reading Knowledge Cafe! Subscribe for free to receive new posts and support my work. Subscribed WHY In today's era, architectures are becoming increasingly large, complex, and fast-paced due to the faster development and deployment of software by distributed teams with the help of DevOps, continuous delivery, and agile development methodo...

Overriding Vs Hiding Methods


Instance Methods


An instance method in a subclass with the same signature (name, plus the number and the type of its parameters) and return type as an instance method in the superclass overrides the superclass's method.

The ability of a subclass to override a method allows a class to inherit from a superclass whose behavior is "close enough" and then to modify behavior as needed. The overriding method has the same name, number and type of parameters, and return type as the method it overrides. An overriding method can also return a subtype of the type returned by the overridden method. This is called a covariant return type.

When overriding a method, you might want to use the @Override annotation that instructs the compiler that you intend to override a method in the superclass. If, for some reason, the compiler detects that the method does not exist in one of the superclasses, it will generate an error.

If a subclass defines a class method with the same signature as a class method in the superclass, the method in the subclass hides the one in the superclass.

The distinction between hiding and overriding has important implications. The version of the overridden method that gets invoked is the one in the subclass. The version of the hidden method that gets invoked depends on whether it is invoked from the superclass or the subclass. Let's look at an example that contains two classes.

  1. If both method in parent class and child class are an instance method, it called overrides.

  2. If both method in parent class and child class are static method, it called hiding.

  3. One method cant be static in parent and as an instance in the child. and visa versa.


package methodhidding;

public class Animal {

 public static void sleeping() {
  System.out.println("animal.Sleeping");
 }

 public void eat() {
  System.out.println("animal.eating");
 }

 public Animal() {
  // This will always call Animal.sleeping(), since it can't be overriden,because it is static.
  sleeping();
  // This will call the eat() defined in overriding classes.
  eat();
 }
}


package methodhidding;

public class Dog extends Animal {
 public static void sleeping() {
  // This method merely hides Animal.sleeping(), making it uncallable, but
  // does not override it, or alter calls to it in any way.
  System.out.println("dog.something");
 }

 public void eat() {
  // This method overrides eat(), and will affect calls to eat()
  System.out.println("dog.eating");
 }

 public Dog() {
  super();
 }

 public static void main(String[] args) {
  new Dog();
 }
}

Output

animal.Sleeping
dog.eating

Popular posts from this blog

Chain of responsibility using Spring @Autowired List

Iterate Through a HashMap

Under the Hood: Understanding the Gossip Protocol in Apache Cassandra