Am I doing it right? Using Interface in my program for the reason that I have I'm gonna use insert() update() delete() many times. Is what I am doing correct? I'm trying to overload Insert() by adding parameter values from a culomn of the table.
This is actually an anti-pattern. I even remember reading an article about it a long time ago but unfortunately I can't give a concrete reference to it. I made pretty much the same mistake back when I was still new to OO design and I guess many others do the same at some point.
One problem is over-generalization or over-abstraction. While generalization/abstraction can be good, going overboard with it can make your programs overly-complex and difficult to follow, therefore making them difficult to maintain and extend. You have to learn how to strike a balance between specialization and generalization and unfortunately, that skill is developed only with practice, experience and the ability to recognize anti-patterns like this among others.
Another problem is a lack of separation of concerns. This makes it harder to protect different parts of your application code from undesired side-effects when you make changes. Application layering helps to separate different concerns from each other. In this case, the concern of performing CRUD operations should be kept separate from domain concerns such as what kind of attributes an object has and business behavior related to its attributes. Typically, separation of concerns is achieved by having a Domain layer that takes care of "business" logic and a persistence layer comprised of Data Access Objects that know how to perform CRUD operations pertaining to specific domain objects.
You might ask "Well, isn't CRUD part of an object's business behavior?" The answer is no, not in most cases. CRUD is related to persistence, usually involving some kind of data repository such as a relational database. These should be kept separate and independent from Domain behavior that isn't really affected by how attributes are persisted.
Another problem specific to the code you wrote is that you are passing way to many parameters to your insert method. I suspect you'll do the same thing with your update method as well. Too many parameters is a "code smell" -- something that is not good. It makes it harder to use the method and it's also more difficult to maintain.
Joined: Apr 04, 2012
I have many parameters.. those parameters are the column of the table and the textfields of my view. So with regards to passing this values, what you guys can advice to me? I first i did not place a parameter. like I instantiated class B from A then A from B to get the values on the view but it will loop and spring will do an error. I am using struts2 by the way.
I gave you a link before - here it is again: too many parameters code smell - follow the link and read about the problem and possible ways to remedy it.
Joined: Apr 04, 2012
I already read one actually on the stock overflow on your link. They have lots of answers, the other ones are like exact 3 or less and the other ones said that it should be the minimum you need. Anyway, what design pattern you guys used with crud? I am reading the headfirst design pattern. And chapter one talks about interfaces to be use because like ducks, there are ducks that fly, could not fly, a rubber duck. etc