Skip to content

Commit 08e7533

Browse files
Commit ithsjava25#2 - Added abstract Product base class
1 parent bb1175b commit 08e7533

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.example;
2+
3+
import java.math.BigDecimal;
4+
import java.util.Objects;
5+
import java.util.UUID;
6+
7+
/*
8+
* Abstrakt basklass för produkter
9+
* Innehåller id, namn, kategori och pris
10+
*/
11+
public abstract class Product {
12+
13+
private final UUID id;
14+
private final String name;
15+
private final Category category;
16+
private BigDecimal price;
17+
18+
protected Product(UUID id, String name, Category category, BigDecimal price) {
19+
this.id = Objects.requireNonNull(id);
20+
this.name = Objects.requireNonNull(name);
21+
this.category = Objects.requireNonNull(category);
22+
this.price = Objects.requireNonNull(price);
23+
}
24+
25+
//Getters
26+
public UUID uuid() { return id; }
27+
public String name() { return name; }
28+
public Category category() { return category; }
29+
public BigDecimal price() { return price; }
30+
31+
//Setter för pris
32+
public void price(BigDecimal newPrice) { this.price = Objects.requireNonNull(newPrice); }
33+
34+
//Abstrakt metod för produktdetaljer
35+
public abstract String productDetails();
36+
}

0 commit comments

Comments
 (0)