What should be placed in the constructor and what should be just one field, I know that you can add things without them Can be started without the manufacturer, here are two examples, I'm just as unsure as to which one is best to use and the reason behind it.
Example 1:
Purchase a public class order {Private string date; Private string client ID; Private string product code; Private Ent Quantity; Private Entitlement; Private-priced price pyRunit; Private customer clientele; // that part of which I am changing the public purchase order (order date, string id, product product, int volume) {this.discountRate = customer.getDiscountRate (); This.date = date.getDate (); This.customerID = customer.getCustomerID (); This.productCode = product.getProductCode (); This.quantity = Quantity; This.pricePerUnit = product.getPricePerUnit (); }
Example 2:
Purchase a public class order {Private string date; Private string client ID; Private string product code; Private Ent Quantity; Private Entitlement; Private-priced price pyRunit; Public shopping order (order date date, customer customer, product product, int volume) {this.discountRate = customer.getDiscountRate (); This.date = date.getDate (); This.customerID = customer.getCustomerID (); This.productCode = product.getProductCode (); This.quantity = Quantity; This.pricePerUnit = product.getPricePerUnit (); }
Note that I can put the customer's client in the constructor or just keep it as a variable. If it is in the Constructor, then it means that if any object is made up of this class then it should also be aware of customer details. But both work is fine, what is the best option and reason for it?
What do you pass as a parameter in the form of an object Created in other classes such as
customer client details contactor = new customer details ();
Then you can go
purchase order purchase = new purchase order (customer inventor, other parameters)
You want to change the object that you create from the previous class, and instead you want to create a new one for another category, you can make it just one variable, as shown in the first example.
Private customer client;
Constructors are mainly the way to take variables from other classes, such as using your main category and those variables, to create those methods which affect them or Things add up. I hope I kind of helped, a good day!
No comments:
Post a Comment