From 4e1d6e302cd9519009618394b5bbac8b34cdbc2e Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Thu, 6 Aug 2015 12:53:11 +0200 Subject: [PATCH] =?utf8?q?Introduced=20protected=20setter.=20Setters=20can?= =?utf8?q?=20change=20attributes=20in=20an=20object,=20which=20is=20not=20?= =?utf8?q?always=20wanted,=20right=3F=20:-)=20Signed-off-by:Roland=20H?= =?utf8?q?=C3=A4der=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../pizzaservice/product/PizzaProduct.java | 54 +++++++++++++++---- .../pizzaservice/product/Product.java | 2 +- 2 files changed, 44 insertions(+), 12 deletions(-) diff --git a/src/java/org/mxchange/pizzaservice/product/PizzaProduct.java b/src/java/org/mxchange/pizzaservice/product/PizzaProduct.java index fe14f93a..a287754c 100644 --- a/src/java/org/mxchange/pizzaservice/product/PizzaProduct.java +++ b/src/java/org/mxchange/pizzaservice/product/PizzaProduct.java @@ -32,17 +32,17 @@ public class PizzaProduct extends BaseFrameworkSystem implements Product { /** * Name of product */ - private final String name; + private String name; /** * Price of product */ - private final float price; + private float price; /** * Title of product */ - private final String title; + private String title; /** * Constructor for products with a name and a price. @@ -52,9 +52,9 @@ public class PizzaProduct extends BaseFrameworkSystem implements Product { * @param price Price */ public PizzaProduct (final String name, final String title, final float price) { - this.name = name; - this.title = title; - this.price = price; + this.setName(name); + this.setTitle(title); + this.setPrice(price); } /** @@ -62,38 +62,70 @@ public class PizzaProduct extends BaseFrameworkSystem implements Product { * @return the name */ @Override - public String getName () { + public final String getName () { return this.name; } + /** + * Name of product + * @param name the name to set + */ + protected final void setName (final String name) { + this.name = name; + } + /** * Price of product * @return the price */ @Override - public Float getPrice () { + public final float getPrice () { return this.price; } + /** + * Price of product + * @param price the price to set + */ + protected final void setPrice (final float price) { + this.price = price; + } + /** * Title of product * @return the title */ @Override - public String getTitle () { + public final String getTitle () { return this.title; } + /** + * Title of product + * @param title the title to set + */ + protected final void setTitle (final String title) { + this.title = title; + } + /** * Whether this product is choosen (default: false) * * @return the choosen */ @Override - public boolean isChoosen () { + public final boolean isChoosen () { return this.choosen; } + /** + * Whether this product is choosen (default: false) + * @param choosen the choosen to set + */ + protected final void setChoosen (boolean choosen) { + this.choosen = choosen; + } + /** * Marks product as choosen */ @@ -101,6 +133,6 @@ public class PizzaProduct extends BaseFrameworkSystem implements Product { public void markAsChoosen () { // Set it this.getLogger().debug(MessageFormat.format("product={0} marked as choosen.", this.getName())); - this.choosen = true; + this.setChoosen(true); } } diff --git a/src/java/org/mxchange/pizzaservice/product/Product.java b/src/java/org/mxchange/pizzaservice/product/Product.java index 126d6aac..71cca43c 100644 --- a/src/java/org/mxchange/pizzaservice/product/Product.java +++ b/src/java/org/mxchange/pizzaservice/product/Product.java @@ -42,7 +42,7 @@ public interface Product extends FrameworkInterface { * * @return Single price of product */ - public Float getPrice (); + public float getPrice (); /** * Whether this product is choosen (default: false) -- 2.39.5