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

  • Home
  • SEARCH
  • 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 652967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:19:50+00:00 2026-05-13T22:19:50+00:00

So I’m working on rewriting a program for a professor, and I have some

  • 0

So I’m working on rewriting a program for a professor, and I have some questions related to the Model-View-Controller pattern. The program is called GraphViewer and is used to design and view graphs (as in Graph Theory, not Statistics). So far I have planned the structure thus:

  • Models
    • VertexModel – Has id, location, color, and a collection of edges it is coincident to
    • EdgeModel – Has the two vertices it spans, weight, color, and a couple other things
    • GraphModel – Primarily, but not just, a collection of vertices and a collection of edges
  • Views
    • VertexView – Paints its vertex, and has its own properties
    • EdgeView – Paints its edge, and also has some of its own properties
    • GraphView – Basically a JPanel that has a collection of vertex and edge views, when it gets a paint command, it also iterates through each collection of views and issues a paint command to them
  • Controllers
    • GraphController – Takes care of interpreting user gestures for adding vertices, edges, etc. and updates the model.

Now the first question I have is related to this plan: Should each model have a view–even though only the graphmodel is a JComponent? Now part of me says yes–because each vertex and edge might be drawn differently. But another part of me screams no to the kind-of parallel-list structure of a graphview having collections of views that correspond to models in the collections of the graphview’s graphmodel (boy that’s complicated). And somehow, I have to work in that the whole graphview must repaint if a vertex or edge model changes. I suppose the answer to this is also related to whether each model gets a controller. (Am I just approaching this wrong?)

Somewhat tied to the answer of the first question is my second: how will I know to notify the graphview if a vertexmodel is added to the graphmodel’s collection? If a whole new collection is set, it’ll notify the view when it enters the setEdges() method. But what if I have to write getEdges().add(…)? Now the graphview needs to be notified of an update, but setEdges was never called…

Thanks a bunch, as you can tell I’m kinda new to design patterns!

  • 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-13T22:19:51+00:00Added an answer on May 13, 2026 at 10:19 pm

    Don’t expose the private Collection member of the model, thus not allowing a call such as getEdges().add(…)

    Rather, expose an API to allow adding/removing edges, and you can then make use of the Observer pattern to notify the view when the model changes.

    Simplistically, and only dealing with Edges…

    public class EdgeModel extends AbstractCollection<Edge> implements Observable {
        private List<Edge> edges = new ArrayList<Edge>();
        @Override public Iterator<Edge> iterator() { return edges.iterator(); }
        @Override public int size() { return edges.size(); }
        @Override public boolean add(Edge edge) {
            if (edges.add(edge)) {
                this.notifyObservers();
                return true;
            }
            return false;
        }
    
        // other stuff for Observable
    }
    
    public class EdgeView implements Observer {
        public void setModel(EdgeModel model) {
            model.addObserver(this);
        }
        public void update(Observable o, Object arg) {
            // model o has changed... update something visual I guess
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 322k
  • Answers 322k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I have this in my .vimrc: if exists('+autochdir') set autochdir… May 14, 2026 at 12:53 am
  • Editorial Team
    Editorial Team added an answer The standard algorithm std::sort requires random access iterators, which std::list<>::iterators… May 14, 2026 at 12:53 am
  • Editorial Team
    Editorial Team added an answer In the beginning, only return the most suitable type (Joda… May 14, 2026 at 12:53 am

Related Questions

I want use html5's new tag to play a wav file (currently only supported
In order to apply a triggered animation to all ToolTip s in my app,
this is what i have right now Drawing an RSS feed into the php,
I have text I am displaying in SIlverlight that is coming from a CMS
I have a French site that I want to parse, but am running into

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.