Solved

Class call and invoke

Posted on 2011-03-01
5
247 Views
Last Modified: 2012-05-11
I need to use for the same class two different communication ways:
1. I need to call it from toggle button
Abc abc = new Abc();
abc.method1();
2. At the same time this class Abc created
private static Abc abc = new Abc();
public static Abc getInstance() {
return instance;
}
I have to use 1 way in jToggleButton to change boolean value , I try to do it with invoking instance, but it doesn't work.
Please advice.
0
Comment
Question by:gbcbr
  • 2
  • 2
5 Comments
 
LVL 47

Expert Comment

by:for_yan
ID: 35008145
If it has public constructor why would you use second way? If it does not have public constructor you cannot use it in the first way.
0
 
LVL 26

Assisted Solution

by:ksivananth
ksivananth earned 100 total points
ID: 35008159
you need to invoke the getInstance method in all the place instead of new ABC()!
0
 

Author Comment

by:gbcbr
ID: 35008638
>> If it has public constructor why would you use second way?
Please explain.
I use second way because this class DecisionCenter has to collect few boolean values from different classes and if all this values lay down into my puzzle correct it will allow deal.
0
 
LVL 47

Accepted Solution

by:
for_yan earned 400 total points
ID: 35008915
If you collect boolean or double values in DC why this has anything to do with the way you access your ABC class ? Please, explain it to yourself and to me in plain words.

As you can see in this discussion there are very few classes which have both public constructore and getInstance mechanism. Why do you want to be so special?  Do like everyone else - either  - or. It is always easier to be like the majority
http://www.velocityreviews.com/forums/t140755-constructor-or-getinstance-method.html
0
 

Author Closing Comment

by:gbcbr
ID: 35009046
Thank you for very good link to discussion
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
mapAB Challlenge 35 128
JList custom Cell Renderer refresh 15 53
Cipher Configuration on Apache HTTPD 4 53
expectj telnet failing 5 26
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now