Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6138781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:54:31+00:00 2026-05-23T17:54:31+00:00

I am currently writing a program which is having a lot of code duplication

  • 0

I am currently writing a program which is having a lot of code duplication between the GUI aspect and the data storage aspect, and I was wondering if my proposed solution follows acceptable design principles.

Basically, I have some Data objects, which have a List holding some more information. Then the GUI displays the object, and a JList which displays all the information in the Data object’s List. In the GUI, users can add or remove information to the object’s list, and this is visually reflected in the JList.

However, this results in me having to maintain the GUI JList and the object List separately:

private void addInformation(String s) {
    this.listmodel.addElement(s);
    this.dataObject.getList().add(s);
}

(Obviously that is a very simple example but you get the idea). It also means that I’m using up twice as much memory holding both lists. Would it be acceptable for me to create a class which implemented both the ListModel and the List interfaces and then only need to update the single combined list/listmodel? I’m still studying at uni and I want to make this project the best I possibly can in terms of maintainability by others and adherence to best practices.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T17:54:32+00:00Added an answer on May 23, 2026 at 5:54 pm

    Your GUI should not hold information about the state of the data model. It would be better to separate it up into a Model-View-Controller (MVC) design. Where the controller is responsible for object creation and updating the model and view accordingly. Your actual view should just be responsible for screen display by passing arguments to it to display. This way the view and model don’t need to know anything about each other and there will only be one data model.

    If your having to keep both lists consistent then something is wrong with your design and will probably introduce more bugs into the code.

    See here for MVC details.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently writing a c++ program which should write me a png file as
I am currently writing a program which takes user input and creates rows of
I am currently writing a LISP program which analyses the CR results in the
I'm currently writing a program to generate really enormous (65536x65536 pixels and above) Mandelbrot
Our company is currently writing a GUI automation testing tool for compact framework applications.
I'm currently writing an interface to allow applications to send exception data to a
I'm currently writing a TYPO3 extension which is configured with a list of tt_content
I am currently working on a project with which I need to program up
I'm having a problem designing part of my program (not writing it, for once!).
I am currently writing an open source SDK for a program that I use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.