G
GiJeet
Hello, I'm new to OOP and C# and I have a design question.
Hypothetically, let's say I have a bookstore business with stores in
several locations. I get a shipment of books into my central
warehouse. I then need to distribute the books to different stores.
When new books get added to a store, I want to fire an event that will
notify people local to that bookstore that a new book in the category
of their interest has arrived so they can come in and look it over -
and hopefully buy.
Now I have a book class and a bookstore class. I want to create a
book instance for each book (title, author, isbn, price, category,
etc.) received and I want to create a bookstore instance of each
location.
So here's the design question:
I was thinking of having an AddToStore method in the book class and an
array list of bookstores as part of each book instance. Then I call
the AddToStore method and the book will loop thru it's array of
bookstores and add itself to each bookstore, since in real life that's
what we do - we add books to bookstores.
However, then I have the same instance reference of the book at each
store right?. This defeats the idea of having an individual
WasNoticeSent flag on the book to indicate that a notice was sent to
the local customers for this book from a specific bookstore. That is,
if I set the flag for bookstore1 to true, then when bookstore2 goes to
check if the notice was sent for the customers of that store the flag
will indicate it was and it really wasn't. Maybe clone each book for
each store?
Or....should I loop thru the bookstores and create a separate instance
of each book for each bookstore. This seems like extra work since
most of the information for a book doesn't change for each bookstore -
same title, isbn, price, etc.
TIA
Gi
Hypothetically, let's say I have a bookstore business with stores in
several locations. I get a shipment of books into my central
warehouse. I then need to distribute the books to different stores.
When new books get added to a store, I want to fire an event that will
notify people local to that bookstore that a new book in the category
of their interest has arrived so they can come in and look it over -
and hopefully buy.
Now I have a book class and a bookstore class. I want to create a
book instance for each book (title, author, isbn, price, category,
etc.) received and I want to create a bookstore instance of each
location.
So here's the design question:
I was thinking of having an AddToStore method in the book class and an
array list of bookstores as part of each book instance. Then I call
the AddToStore method and the book will loop thru it's array of
bookstores and add itself to each bookstore, since in real life that's
what we do - we add books to bookstores.
However, then I have the same instance reference of the book at each
store right?. This defeats the idea of having an individual
WasNoticeSent flag on the book to indicate that a notice was sent to
the local customers for this book from a specific bookstore. That is,
if I set the flag for bookstore1 to true, then when bookstore2 goes to
check if the notice was sent for the customers of that store the flag
will indicate it was and it really wasn't. Maybe clone each book for
each store?
Or....should I loop thru the bookstores and create a separate instance
of each book for each bookstore. This seems like extra work since
most of the information for a book doesn't change for each bookstore -
same title, isbn, price, etc.
TIA
Gi