1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Rep Power

    Help!! Do I really need to pass objects through methods???

    I often come across the same problem while coding and was wondering how others get around it (if at all). The problem is when I need to pass information across multiple levels (usually 3 or more). For example, assuming a simple java servlet with a controller layer, a service layer and a dao layer. Now, suppose I want to pass an object which comes from the controller layer (maybe a User object from the Request) to the DAO layer. I usually end up having to pass the object through the Service layer even though the Service doesn't do anything with the object directly, it just passes it along to the DAO layer. Is there a pattern that would allow me to clean this up? It isn't about the specific case, I've also had this happen when refactoring a large method (breaking it up into smaller methods in the same class) and found this similar problem.
  2. #2
  3. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Feb 2004
    Mobile, Alabama
    Rep Power
    Have you tried using a Session variable?

IMN logo majestic logo threadwatch logo seochat tools logo