Giter VIP home page Giter VIP logo

Comments (2)

vhpx avatar vhpx commented on May 26, 2024 1

The transaction object is what you need to link Account, Item, and the borrowing state together.

class Transaction {
     Account account;
     Item item;
     boolean returned = false;

     void resolve() => returned = true;
     // Something for setting returned to false here
     // or just change it to setReturned(bool state) for simplicity.
}

If you want to perform a rent action, it would be best served on an Account object. Think of it like this:

if (PersonA.canRent(book1)) // Only check if this account can rent the given item
    PersonA.rent(book1);    // Create a transaction and call ItemManager.decreaseStock(book1)

Which is a valid case for using the rent() method on the Account without the much-needed confusion. For handling the decreasement of items, just call ItemManager.decreaseStock(book1), which by default decreases the item's stock by 1.

NOTE: You can also create an overloaded function:

void decreaseStock(Item item, int amount);

to decrease the stock by any amount of your choice.

Those are just a few basic ideas you'll have to keep in mind. Let me know if you need more clarifications on this topic, I'll be happy to help.

from video-store-manager.

thu-ngx avatar thu-ngx commented on May 26, 2024

@vhpx I have some confusions:

  • Where can we put the method that perform renting item and returning item? In Account class or Transaction class?
    If in Account class, we will check if that item is possible to be rented or not then decrease numCopy and add to current rental list. After that, we will create the transaction.
    If in Transaction class, this class is responsible for all the checking and other tasks like decrease/add when Account call rentItem.

  • Do we need to have add a list of transaction as attribute of Account class?

from video-store-manager.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.