Jump to content
  • Advertisement
Sign in to follow this  

Inner Class Good Code Structure

This topic is 3003 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I have come to a question that I require outside support with. I am creating a class that will parse some html and do some specifics that I can easily separate into 3 different classes. However since we have a large amount of classes and 2 of them will only ever be used inside 1 of them I have created 2 private classes. The problem arises in that the first private class is simply a container
private class Container {
  private DTO dto;
  private boolean found;
The second private class I want to create is one that holds a list of containers and does all logic involved with them.
private class ContainerList {
  private List<Container> containerList = new ArrayList<Container>();
  private boolean findID();
  private void makeNewDTO();
  private void deleteDTO();
Pretty much any logic that has to do with the list of Containers would be done in this private class. This could involve any finds for the entire Container (much of the data in the DTO's are unique). As well as calling outer methods that do specific add and removes for the DB. This could all be done in the outer method but for me it makes more since to organize it like this however I am not completely sure. So is it ever wise to have a private class nested inside another private class? Or should I simply just have a private container class and do any logic with that list inside the outer class (all private methods of course).

Share this post

Link to post
Share on other sites
I would personally go for the private inner class.

But looking at the implementation of Container I wonder if it could be expressed in a different way.

Just having this in ContainerCollection seems an equivalent implementation:
private Collection<DTO> dtos = new ArrayList<DTO>();
private Collection<DTO> foundDtos = new ArrayList<DTO>();

(do you really need a List?, maybe it is a Set implemented with LinkedHashSet)

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!