Solved

Class call and invoke

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
servlet doXXX methods 3 62
how to add new optional parameter to JSP 1 49
CSV file parsing thru Java 13 34
collection output issue 9 39
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

820 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