I have a class named Item. It has the following parameters:
User owner, Category category and String description.
Next to that, I have a subclass named Painting which extends the Item-class. A Painting has two parameters: title and painter.
At some point in the code, I’d like to create a Painting object. It should be possible to run code from a test file that goes like this:
User u1 = new User ("test@test.com");
Category cat = new Category("cat2");
Item painting = sellerMgr.offerPainting(u1, cat, "Selfportret", "Rembrandt");
There should be code in the class sellerMgr which should be able to register (create) that item (as a Painting), so I can use it in a database for example. How do I call that code exactly? I get confused whenever or not to create a new Item or a new Painting, and which parameters to add in the creation code.
You have a new class
you’ll want a constructor that provides two new parameters, String title, User painter
Whenever you want a new instance of a Painter you can call this method that will set up any of the Item variables for you, while introducing the two new parameters you desire. A call could look like either