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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:36:19+00:00 2026-05-25T03:36:19+00:00

I have a Load class and a Cargo class. An instance of Load contains

  • 0

I have a Load class and a Cargo class. An instance of Load contains an instance of Cargo.

class Load {
    Cargo cargo
}

class Cargo {
    String name
    BigDecimal cost
}

Lets say that the name of an instance of Cargo is “rock” and the cost is “11.11”. Now I use this instance of Cargo to create an instance of Load. Now that the instance of Load has been created I don’t want it’s “cargo” to change. For instance, if I change the price of “rock” to “22.22” I don’t want the price of the “cargo” in my instance of Load to change. What is the optimal way to handle such a situation?

  • 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-25T03:36:19+00:00Added an answer on May 25, 2026 at 3:36 am

    Well, if you can only have one Cargo per Load (as per your example), you’ll want to add a cost property to Load. Then you will need to copy over the cost at the time the objects are created. You might be able to do this via an overloaded method in the Load object, or just write your own method to add Cargo to Load.

    If you actually need multiple Cargoes per Load, then you’ll want an intermediate object to represent the connection. This object will store the price at the time they were associated. That might look like:

    class Load {
        LoadCargo loadCargo
    }
    class LoadCargo {
        Cargo cargo
        BigDecimal cost
    }
    class Cargo {
        String name
        BigDecimal cost
    }
    

    Of course, your object model will be a bit more complicated, because of the indirect relationship to Cargo.

    Edit
    Another way to handle the multiple-related situation is to duplicate the Cargo every time the cost is updated. This might be more efficient if you are expecting cost to be mostly static. I’d handle this by adding a field to “disable” items, like so:

    class Cargo {
        String name
        BigDecimal cost
        boolean active = true
    }
    

    I believe you can simply clone the Cargo on update like this:

    oldCargo = Cargo.get(params.id)
    newCargo = new Cargo()
    newCargo.properties = oldCargo.properties
    // now set the new cost, etc.
    newCargo.save()
    oldCargo.active = false
    oldCargo.save()
    

    That’s just a guess, it probably is broken.

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

Sidebar

Related Questions

I have this class that have a function to load other classes and create
I have a class - XClass, that I want to load into an array
I have the class name stored in a property file. I know that the
Lets say I have a class like this in class1.vb: Public Class my_class Public
If I have a bundle that contains a class and some resources used by
I have a class already load inside __construct() of my page, after that once
Ok guys. I have a link with class name more_updates. I want the load
I have a load of <div> 's, all with the class name of '
I have an entity loaded by Hibernate (via EntityManager ): User u = em.load(User.class,
I have to load huge (3000x3000) pictures in SWFLoader, and no problems with that

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.