aspose file tools*
The moose likes Beginning Java and the fly likes static and non-static relationship question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "static and non-static relationship question" Watch "static and non-static relationship question" New topic
Author

static and non-static relationship question

Shay Gaghe
Ranch Hand

Joined: Sep 03, 2001
Posts: 102
Hello Coders J
My program consist of several classes. I find it more readable,logic and useful to declare all the methods in all the classes �static� and get access by Class.member().
The problem showed up when I must use a java biuld-in method( as Component.remove ) within my static method , then I receive compile error.
The first alternative is to create the class instance inside the static my static method , the second is to use interface which declare its member as static final. The two ways doesn�t fit to my needs , do anyone know another way?
Thanks in advance
Shay
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
It is really hard to say without seeing any code, but if you pass a reference to the instance of the Component as a parameter to the static method and use it as a local variable you can act on it.
Many of the methods in the API are static and take in objects.


"JavaRanch, where the deer and the Certified play" - David O'Meara
Shay Gaghe
Ranch Hand

Joined: Sep 03, 2001
Posts: 102
Hello
i feel like an OOP's traitor I�ve been told that I violate the OOP design�s rules in Java�s OOP design whenever I use only static members instead of creating class instances. Can anyone tell about the deficiencies and advantages of using the both form static and OOP?
thanks
Shay Gage
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 986

I guess I don't understand why you want to declare everything static. You say it is more "readable, logic and useful", but I don't know what you mean.
You need to be careful if you are declaring everything static. static means you only have one copy and if you have different code all calling the same static method you can get confusing results.


Please ignore post, I have no idea what I am talking about.
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9046
    
  10
If you are using all static code, it seems that you are only doing procedural programming and using classes as functions rather than using abstraction, polymorphism, inheritance, and encapsulation which are the cornerstones of OOP.

JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: static and non-static relationship question