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 8852963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:31:54+00:00 2026-06-14T13:31:54+00:00

I have a Compressor component in my model: public class Compressor extends MComponent {

  • 0

I have a Compressor component in my model:

public class Compressor extends MComponent {    

    public static final double THRESHOLD_MAX = 1; 
    public static final double THRESHOLD_MIN = 0;
    public static final double THRESHOLD_DEFAULT = 1; 
    private double threshold; 

    /* <snip> - many other parameters*/

    public void setThreshold(double v)      { this.threshold = v; }
}

And for this particular application, I have a GUI I’m constructing with Java Swing, which adds sliders, buttons etc to display and control the Compressors parameters.

Now some of these sliders should operate on a linear scale, while others should operate on a logarithmic/expontial scale (where a move of the slider will make a small change of value in the lower end, and a large change of value at the upper end).

I have a GuiConstructor class that handily creates sliders and and their move events, so that they’ll act appropriately given a Min value, max value, Exponential/Linear type, and a q value (for exponential types).

    gc.addSliderPanel(
            panel,
            "Threshold",
            Compressor.THRESHOLD_MIN,
            Compressor.THRESHOLD_MAX,
            c.getThreshold(),
            GuiConstructor.Scale.LINEAR, /*<-- this line*/
            0,
            new SetThreshold(c),
            DEFAULT_SLIDER_GRAINS,
            GuiConstructor.SliderValueType.FLOAT); 

The question is – should I be declaring the display type in the view or would be ok to specify the display type in the model?

eg.

public class Compressor extends MComponent {    

    public static final double THRESHOLD_MAX = 1; 
    public static final double THRESHOLD_MIN = 0;
    public static final double THRESHOLD_DEFAULT = 1;
    public static final GuiConstructor.Scale THRESHOLD_SCALETYPE = GuiConstructor.Scale.LINEAR;  
    private double threshold;           

I like the idea of specifying it in the model, as I only need to think about the display parameters when I create each component, rather than when I’m putting it together.

  • 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-06-14T13:31:55+00:00Added an answer on June 14, 2026 at 1:31 pm

    A model can most certainly contain attributes that describe how the model works: that it is a linear vs. exponential compressor. However, it should never have a direct reference to a specific view object such as you propose. Instead, make the attribute descriptive in nature, and have the “GuiConstructor” select the right view based on the attribute’s value.

    For instance:

    // Not apart of the View, but in the model package:    
    public enum ScaleType {
        LINEAR,
        EXPONENTIAL;
    }
    
    public class Compressor extends MComponent {    
    
        private ScaleType scaleType = ScaleType.LINEAR;
        public ScaleType getScaleType() { return this.scaleType; }
    
    }
    
        //  In your construction method:
        gc.addSliderPanel(
                panel,
                "Threshold",
                Compressor.THRESHOLD_MIN,
                Compressor.THRESHOLD_MAX,
                c.getThreshold(),
                c.getScaleType(), /*<-- this line*/
                0,
                new SetThreshold(c),
                DEFAULT_SLIDER_GRAINS,
                GuiConstructor.SliderValueType.FLOAT);
    

    The overriding principle, is that the Model should have no knowledge of the view. The view object should be changeable without the model needing to change. Or to put it another way, assume that an entirely different set of UI classes are built. The model class should not require a coding change.

    Here are a couple of friendly observations on your code:

    1. I assumed above that the “GuiConstructor.Scale” was an enumeration. If it isn’t, please consider using one instead of static finals.
    2. I recommend renaming ‘GuiConstructor’ to ‘GuiFactory’ or ‘GuiBuilder’. A ‘constructor’ has too specific of an OO meaning to be used in the context you are using it.
    3. You may be over-using Class attributes (the final static attributes) instead of using the object’s attributes to describe the compressor. Why not have the thresholds and scale be attributes of an object? Otherwise, creating child LinearCompressor or ExponentialCompressor classes will require their own references (rather than using overrides).
    4. I have no idea what ‘new SetThreshold(c)’ means. That looks like you have named a Class with a name reminiscent of a setter method on a class. Consider renaming that object.

    Hope this helps,

    john…

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

Sidebar

Related Questions

I have the following script transformation component. public class ScriptMain : UserComponent { Regex
I have a project for my Data Structures class, which is a file compressor
I am looking at Yahoo's YUI compressor executable jar and they have this class,
I have used Yahoo YUI Compressor for .net to minify my css and js
I have no idea of what compressor modules like gzip are, I have never
I have an LZW compressor/decompressor written in C. The initial table consists of ASCII
I have an app(django-compressor) that I only want to run on my local machine
I have a large swing component to write to TIFF. The component is too
I have this situation, I am using Yahoo Yui Compressor and my MSBuild file
I have interesting question. Do you know of any component to read/write PVRTC iPhone

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.