title: String Switch Implementation alternatives in OOP
body: <p>I have two objects say Object a and Object b. Both of these objects have some properties say name, age etc. I want to write a method where I pass some string value as a parameter to this method and it prints some value for both the objects. Which value to print is decided by the String that is being passed to the method. To be more clear:-</p>
  
  <pre><code>Class A{
  String name;
  String age;
  //getters and setters for name and age
  }
  
  Class B{ 
  String salary;
  String level;
  //getters and setters for name and age
  }
  
  
  
  
  public String getValue(String attribute)
  {
      switch(attribute)
      {
          case "name":
          System.out.println(a.getName());
          System.out.println(b.getSalary());
          break;
          case "age":
          System.out.println(a.getAge());
          System.out.println(b.getLevel());
          break;
      }
  }
  </code></pre>
  
  <p>Now using switch statements does the job. But I have read that switch statements are not a good practice for OO design. What are the other ways I can do this? I have read something about using enums but I am not very clear about it.</p>