Solved

Class call and invoke

Posted on 2011-03-01
5
236 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

758 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

20 Experts available now in Live!

Get 1:1 Help Now