Days before, I created Question, Quiz, and Main classes. One Quiz has one or more Questions. From the main class I first create Question objects (the constructor accepts an array of numbers). The Quiz is like when I display the questions I omit the last number of the array and the user will try to figure out that number. Then from Main I created a Quiz Object. From Main I only call methods of the Quiz class and from Quiz Class I only call methods in Question class.  Then I also created a web application (with JSP and Servlets) which uses the same Question and Quiz classes but not Main. Instead of Main I used JSP and Servlets to display the data. So without modifying the model classes(Quiz and Question) I am able to use them from other applications. But now, I need to add a HINT, which will give the user hints for every questions. If I go and modify those 2 model classes, I am going to violate the Open-Close principle. If I am going to create a class called Hint(one hint per question) and extend from question class, it doesn't make a sense because Hint is not a Question. But Question has a hint.Can you please guide how to have a HINT in my application so that I will use the previous classes without modification and violating any OOP concepts?
How to apply one of the OOP concepts (Closed for Modification and Open for extension)?
java;object oriented;coding standards;code reuse;patterns and practices
I don't see why you would want to be so picky about following OOP principles. OOP is great, and the principles are sound, but then again each project has it's own particularities. Wanting to be OOP-perfect at all costs sounds like a drawback to me.The more I code, the more flexible I am with those principles. They are not here to make your life harder, they are here to make your coding cleaner. If your code is clean and makes sense, to hell with principles.Adding a hint method to your question class, that returns nothing if there is no hint or that is not called from your apps that don't need it changes nothing to the portability of your code and your commitment to OOP.As for extending the question class, it seems to me that you are having a nomenclature problem. Your issue is that if you call your extended question class hint, it lacks sense because hint isn't a question. But in that case, if your extended class, instead of hint, was called question_with_hint, then it would make sense, right? You are calling it hint just to make it shorter and more usable. Call it question_extended if it eases your mind.