Results 1 to 3 of 3
Thread: Accessing Object methods
- 02-13-2013, 07:39 AM #1
Member
- Join Date
- Feb 2013
- Posts
- 2
- Rep Power
- 0
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
- 02-13-2013, 12:21 PM #2
Senior Member
- Join Date
- Oct 2011
- Location
- Sweden
- Posts
- 123
- Rep Power
- 0
Re: Accessing Object methods
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 JavaThe 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.
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!
- 02-13-2013, 12:38 PM #3
Member
- Join Date
- Feb 2013
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
Accessing methods from object in another class.
By blug in forum New To JavaReplies: 1Last Post: 10-16-2012, 02:58 PM -
Accessing an object from within another object from the same type in Java
By mhasgari in forum Threads and SynchronizationReplies: 5Last Post: 06-20-2011, 04:21 PM -
Problems accessing methods in an object.
By Kevinius in forum New To JavaReplies: 2Last Post: 03-05-2011, 10:52 AM -
accessing variable/methods of a instantiated object
By hariza in forum AWT / SwingReplies: 5Last Post: 10-11-2010, 01:16 AM -
Accessing GUI object methods
By km0r3 in forum AWT / SwingReplies: 5Last Post: 10-06-2010, 01:39 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks