Results 1 to 3 of 3
  1. #1
    binary_matter is offline Member
    Join Date
    Feb 2013
    Posts
    2
    Rep Power
    0

    Default Accessing Object methods

    Hello all,

    I have three classes

    class A , B , C

    Class A is a JFrame with data

    Class B is a JPanel with data

    Class C is a JFrame with data

    Class C is opened from Class B

    When something changes in class C it should change some data in Class A

    What im doing at the moment is passing ClassA to B then to C in the constructor

    Is there a better way to do this ?
    Can there be a interface or something?

    When a program keeps on growing the object passing becomes quite difficult to handle
    and i would like to stay away from any static methods

    Thank you all

  2. #2
    Zyril is offline Senior Member
    Join Date
    Oct 2011
    Location
    Sweden
    Posts
    124
    Rep Power
    0

    Default Re: Accessing Object methods

    Quote Originally Posted by binary_matter View Post
    Can there be a interface or something?
    Hi, and yes, there is a nice design pattern that makes use of an interface and that does the exact thing that you are looking for. It's called the Observer-pattern, or sometimes referred to as Publisher/Subscriber-pattern.

    The observer pattern defines a one-to-many dependency between objects so that when one object changes state, all of its dependents are notified and updated automatically.
    Take a look here: Observer Design Pattern in Java

    Also, this Youtube video might be helpful to understanding this more easily. It might seem low quality but I think he explains it nicely:
    The Observer Design Pattern - YouTube


    Any questions, feel free to ask!

  3. #3
    binary_matter is offline Member
    Join Date
    Feb 2013
    Posts
    2
    Rep Power
    0

    Default Re: Accessing Object methods

    Quote Originally Posted by Zyril View Post
    Hi, and yes, there is a nice design pattern that makes use of an interface and that does the exact thing that you are looking for. It's called the Observer-pattern, or sometimes referred to as Publisher/Subscriber-pattern.



    Take a look here: Observer Design Pattern in Java

    Also, this Youtube video might be helpful to understanding this more easily. It might seem low quality but I think he explains it nicely:
    The Observer Design Pattern - YouTube


    Any questions, feel free to ask!

    Thank you for the answer , i will look into it and let you know :)

Similar Threads

  1. Replies: 1
    Last Post: 10-16-2012, 02:58 PM
  2. Accessing an object from within another object from the same type in Java
    By mhasgari in forum Threads and Synchronization
    Replies: 5
    Last Post: 06-20-2011, 04:21 PM
  3. Problems accessing methods in an object.
    By Kevinius in forum New To Java
    Replies: 2
    Last Post: 03-05-2011, 10:52 AM
  4. Replies: 5
    Last Post: 10-11-2010, 01:16 AM
  5. Accessing GUI object methods
    By km0r3 in forum AWT / Swing
    Replies: 5
    Last Post: 10-06-2010, 01:39 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •