This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Using Interface in the Design. Overloading Methods from the interface. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Using Interface in the Design. Overloading Methods from the interface." Watch "Using Interface in the Design. Overloading Methods from the interface." New topic
Author

Using Interface in the Design. Overloading Methods from the interface.

victor chiong
Ranch Hand

Joined: Apr 04, 2012
Posts: 73
Hi Gurus,

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.




Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4446
    
    5

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.


Junilu - [How to Ask Questions] [How to Answer Questions]
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4446
    
    5

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.
victor chiong
Ranch Hand

Joined: Apr 04, 2012
Posts: 73
Yeah,

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.

Thanks,
Vic
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4446
    
    5

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.
victor chiong
Ranch Hand

Joined: Apr 04, 2012
Posts: 73
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

Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4446
    
    5

See DAO pattern
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using Interface in the Design. Overloading Methods from the interface.
 
Similar Threads
Creating a more generic DAO (no hibernate) - A good Riddle
Can't generate java classes from WSDL file
Deprecated function authscheme(). Need Help to resolve this issue
Using AbstractTableModel to show data from user defined Classes - problem passing/defining the data
unusual behaviour of subclass of JPanel