I want to model a simple merchant website, with a Visitor, an Account, a Customer and an Administrator.
A Visitor can have a Basket.
A Visitor can become a Customer if it creates or provides Credentials.
A Customer and an Administrator are an Account with Credentials.
class Account {
Credentials credentials;
void logout();
// other account management methods
}
class Admin extends Account {
}
class Visitor {
Basket basket;
// basket management methods
}
class Customer extends Visitor, Account {
// needs a basket and credentials
}
I tried an Account interface, but account management methods have to be implemented both in Customer and Admin, and I don't want to duplicate that code. I saw that default implementation of interface methods exist in Java 8. But is there another way to achieve that without this hack?