Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Why don you put the table structure in a separate Mapper class?

0
10 Posted

Why don you put the table structure in a separate Mapper class?

0

If you have a User class that performs some business logic that doesn’t interact with the database, wouldn’t you want a separate class that mapped a user to the database, either inserting or deleting or what-have-you? I disagree with this idea, for the following reasons: • By having properties and methods for an object contained within more than one class you are breaking the principle of encapsulation. • By having to access one class for database access and another for non-database access you are forcing the calling script to have knowledge of the internals of each class. This breaks the principle of information hiding. A better way to do it would be to have all properties and methods defined within a single class, and if a particular method requires to access the database then it should do so. If this involves communicating with a separate ‘mapper’ class (or in my case a data access object), then so be it. The important thing is that the calling script should not know or even care ab

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123