7
crisz
7y

Tomorrow I'll have my Java exam. Teacher sent us a code example and I analyzed it, it works correctly but it's full of mistakes about polymorphism. I'm fucking afraid

Comments
  • 1
    example, as in something it *should* look like?
  • 0
    @Grom He created the class AddressBook, he created the method addContact(BufferedReader br), he invoke readLine() for each field, but inside the class instead of outside. What if tomorrow another programmer wants to use that class?
  • 1
    i dont really get what the issue is or what that has to do with Polymorphism
  • 1
    Polymorphism is when a class can assume more shapes according to what you want to do. If you create a class which fits only on your code, you're violating polymorphism, aren't you?
  • 1
    i see where you are coming from now. sounds like AddressBook should really either be an interface or implement an interface that declares the method. the problem isnt so much that the code is inside the class. Just that its the only concrete implementation. But thats ok sometimes. We dont always know what parts of our system are gonna need to change. So sometimes its best to just use the simplest implementation, and then build in abstractions like interfaces etc. when we know that a particular module is susceptible to change or will be extended in future. If you try to build all your abstractions right away you end up with an over-engineered implementation.
Add Comment