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
New Contributor
leontager
Posts: 4
Registered: ‎01-11-2010
My Device: 9000
Accepted Solution

program design question

Hi, I am working on my first blackberry program and I'm running into difficulty with my design decision so I'm hoping someone could clarify.

 

Whenever I would program in .Net I would use the MVC model. My control would execute a custom event defined in the controller and my view could capture that event. However, I'm not sure how I can do this for the blackberry. I have a text field in my view and a class that extends buttonfield in the model. I would like to define the button to have a certain effect on the text field but I'm not sure how to pass in the message without passing the screen to each button.

 

How is this genereally done?

 

Thanks for your help

Developer
DAquilina
Posts: 587
Registered: ‎01-19-2010
My Device: BOLD 9700 OS5.0.0.x on Rogers Canada
My Carrier: Rogers

Re: program design question

In terms of accessing the variables, you could use the runtime store or persistent store for a truly Global handling, or you could merely increase the scope to the highest class level and make them public for static access. When the fieldChangeListener detects that the button has been pressed, it affects the change on the now-accessible text/label field.

 

Sorry if I misunderstood your question/intent,

~Dom

----------------------------------------------------------------------------
chown -R us ./base
~J!NX
New Contributor
leontager
Posts: 4
Registered: ‎01-11-2010
My Device: 9000

Re: program design question

so I've made my MainScreen public and static and access the text field in it once the FieldChangeListener on the button is called. Would this be the best design?

Developer
DAquilina
Posts: 587
Registered: ‎01-19-2010
My Device: BOLD 9700 OS5.0.0.x on Rogers Canada
My Carrier: Rogers

Re: program design question

Well technically the best design is a Singleton model, but to be honest I have no idea how they actually work. It all depends on how you look at it. That semi-global variable cannot be accessed outside an instance of your application, and you aren't likely to have a large development team on a BlackBerry app, so the chances of your program losing its security and/or stability due to outside interference is low. I know experienced programmers and professors who are religiously opposed to Global variables, but they certainly have their place, and I don't see any problem with leveraging this functionality as you are proposing. The key thing to remember for BlackBerry development is that mobile devices are not as powerful as a PC or console. Developers are urged to leverage multi-Threading to maximize efficiency, and to avoid garbage collection (in other words, creating variables with limited scope that are freed from memory. This memory must then be systematically freed by the garbage collector). Another good practice is to stick to condensed syntax (aka shorthand).

 

For example:

 

if (event) {/*perform action*/}

 

rather than...

 

if (event == true) {/*perform action*/}

 

 

 

Hope that helps,

~Dom

----------------------------------------------------------------------------
chown -R us ./base
~J!NX
New Contributor
leontager
Posts: 4
Registered: ‎01-11-2010
My Device: 9000

Re: program design question

thanks for your help

Developer
DAquilina
Posts: 587
Registered: ‎01-19-2010
My Device: BOLD 9700 OS5.0.0.x on Rogers Canada
My Carrier: Rogers

Re: program design question

[ Edited ]

Singleton model:

 

http://en.wikipedia.org/wiki/Singleton_pattern

 

Basically it's a means of accessing non-Global variables from anywhere with a high degree of protection. It's an interesting read, but it's also an incredibly advanced programming concept.

 

EDIT: Any time :smileyhappy:

----------------------------------------------------------------------------
chown -R us ./base
~J!NX