Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 107
Registered: ‎08-08-2008
My Device: Not Specified

Need some help with Java Class Blackberry Persistent Opjects

I have a persistent class and need to access the data to from various functions in my main class.

I'm not sure what is the proper way to access the persistent data. It's working both ways but i don't know what is better resource wise.

 

Option #1:

Class myMainClass() { private myPersistentClass persistentData = myPersistentClass.fetch(); public init() { String _data1 = persistentData._Pdata1; String _data2 = persistentData._Pdata2; String _data3 = persistentData._Pdata3; } public workerFunction() { String _data1 = persistentData._Pdata1; String _data2 = persistentData._Pdata2; String _data3 = persistentData._Pdata3; } } Class myPersistentClass() implements Persistable { public String _Pdata1 = "Data 1"; public String _Pdata2 = "Data 2"; public String _Pdata3 = "Data 3"; }

 

Option #2:

 

Class myMainClass() { private myPersistentClass persistentData; public init() { persistentData.fetch(); String _data1 = persistentData._Pdata1; String _data2 = persistentData._Pdata2; String _data3 = persistentData._Pdata3; } public worker() { persistentData.fetch(); String _data1 = persistentData._Pdata1; String _data2 = persistentData._Pdata2; String _data3 = persistentData._Pdata3; } } Class myPersistentClass() implements Persistable { public String _Pdata1 = "Data 1"; public String _Pdata2 = "Data 2"; public String _Pdata3 = "Data 3"; }

 

Should i do a fetch() from within every function as i need it or should I do it globally. This code is running in a library that I call from an alternate entry CLDC app.

 

thanks

 

 

 

Developer
Posts: 5,339
Registered: ‎09-20-2008
My Device: ***
My Carrier: ***

Re: Need some help with Java Class Blackberry Persistent Opjects

[ Edited ]

The main approach of well-designed OOP application - is hiding unecessary classes, methods and fields from outside.

 

In this case you can make myPersistentClass as an internal private static final class MainClass and use fetch() method only when it is necessary.

 

Additional important point: There is a limited qty of object handles into the one device OS context.

 

Due to this fact - try to reduce unecessary object references into your application. Into the first example - it is unecessary object reference declared persistentData

 

Check this document

 

And additional less important point Smiley Happy

 

Do not start class names with small letters. It is against the rules and does a significant negative affect on your karma Smiley Happy

 

Check the following link: http://java.sun.com/docs/codeconv/

 

Message Edited by tbilisoft on 18-12-2008 09:06 PM
Highlighted
Developer
Posts: 107
Registered: ‎08-08-2008
My Device: Not Specified

Re: Need some help with Java Class Blackberry Persistent Opjects

Thanks for the tips tbilisoft.

 

I don't normally name my class with lower case it just happend in my example but i'll make sure to follow the golden rules.