Background
I've designed and implemented a server app - a stateless REST API that mostly deals with customer CRUD operations.
As it is now the server is designed to use modules for each functionality instead of OOP concepts - although the 2 share some analogies AFAIK.
As an exercise, I'm trying to model some aspects in OOP.
Creating a new object is straightforward.
Naturally I'd expect that creating a new Customer would simply be instantiating a new Object.
For example:
// CREATE NEW
// User wants to Insert a new customer.
var customer = new Customer({
name: "John Doe";
});
return "Saved Customer";
What about getting an existing though?
What is considered a reasonable pattern if I instead want to get an existing that's already saved in DB?
For example is this a reasonable API?
// GET EXISTING
// User wants to get existing customer from DB
var customer = new Customer().fromDB({ id: 1 });
return customer;