I'm tackling the following question:
The iterator design pattern is one that has strong encapsulation. As an example; a library wants a book management system. A class for the
book
s storing their details and a class for thelibrary
storing the books and the shelf number. Lets say the library wants the data stored in a database usingJDBC
.How can the Iterator design pattern be implemented using JDBC ensuring encapsulation of the data?
My concern is where the database is being handled and how the data is being shared across the application.
Can the database handler be an inner-class of the library class? Is it then possible to save the data and retrieve it on request without affecting the encapsulation?
I am still learning and have a long way to go so be gentle :)