I am a beginner in Java and have started reading Head First Java by O'Reilly publication. Though I am able to understand most of the concepts of OOP and how they are implemented in Java, one question that has me perplexed is: How do we decide the number of classes a particular application will need? In the book there is an example of a Dot Com Bust game in which 3 different classes are created. One is the GameHelper class, another is the DotCom Class and the third one is DotComBust class. What factors decide how many classes are we gonna have in the application?
Are you really understood OOP or you need to revisit the basic concepts?
You question sounds to me like "someone is asking as how many tables one application should have in its DB model?" and the answer is it totally depends on the architect and there is a famous quote, "No design is wrong!" ...but any design can be improved further considering different aspects
love your job and not your company;
...because you never know when your company will stop loving you!
Joined: Apr 22, 2010
Thanks for the reply. I understand that an architect decides the number of classes to be coded. But what are some of the design considerations that an architect keeps in mind while doing so? To take your DB analogy, DBA might decide number of tables depending on the speed of data retrieval or the ease of access. What derives the number of classes - maintainability probably.. anything apart from that?
There is no really good answer to this question, it depends on the application and there are no hard and fast rule.
In OOP, a class should represent a type of object in your application so the question is how many types of objects are their in your application. Classes should always try to work for themselves, and should work together to achieve the purpose of the application.
But there is more than one way to skin a cat so often two programmers given the same functional requirements might come up with a different set of classes.
In a way you question is meaningless, if you have understood OOP the question always needs to be answered for the particular application requirements and is more a set of questions asking yourself should this be an object repeatedly?