Reputation: 3229
At the moment I have two classes, first one is called "Building"
and second one is called "Happening"
. Every building has its own name, and ArrayList
of events (Happening)
for one day. The class Happening
has start time and end time. There can be many buildings and every building can have multiple events (Happening)
. But as you see I am using two classes to get this job done. I know it is probably the best way, but I am curious if I could handle all this with only one class (Building)
without needing the Happening
class. I tried using Happening
as an inner class, but it won't work for me, because my main method that gets data from Building
also needs to know this class, because my Building
has a method to return all its happenings as an Array. So I am wondering if there is any alternative way of doing this.
Upvotes: 0
Views: 38
Reputation: 12020
Do not consider creating separate classes to be a bad thing. It makes your code easier to read, use and understand. While you undoubtedly could combine these into one class through the use of multi-dimensional lists/arrays or some other hack, the result would be a much less readable codebase. (Think of it as the same reason why, in database design, we try to separate things out into separate tables where we can, unless performance reasons dictate otherwise).
Upvotes: 3