Thanx Yusuf, your advice is right, i should optimise later. I have to admit i am just started exploring Java and the android API, so hence the sloppyness.
The main point is, that being so new, i have to post these kind of questions to take away some insecurity on choices i make. If I understand your point correctly, it is not bad practice what i did. I just need to optimize... Using a dotmanager, isnt it more expensive to go through all the dots an update them. I can imagine by using the architecture as is and not implement another structure, this would be faster. Any ideas on that? Jiri Yusuf T. Mobile wrote: > Code first for simplicity then optimize if/as needed. That being said > (well, more like pontificated, sorry), a simpler design would be to > aggregate all your dots into a DotManager. This would listen and draw > all the dots as needed. Aggregation works if all the dots are similar > enough that their code can be centralized, and if I understand your > problem correctly (all dots listen for the same event and then they > all move), my brilliant and royalty-free design would be appropriate. > > > > Yusuf Saib > Android > ·T· · ·Mobile· stick together > The views, opinions and statements in this email are those of the > author solely in their individual capacity, and do not necessarily > represent those of T-Mobile USA, Inc. > > > > > > On Aug 11, 9:13 am, "jiriheitla...@googlemail.com" > <jiriheitla...@googlemail.com> wrote: >> I was wondering if the following is considered good practice. >> I am creating mulitple Dot instance. A Dot instance is a value object >> containing x,y, color, diameter fields. >> I draw each created Dot to a view: >> <code> >> canvas.drawCircle( dot.getX(),dot.getY(),dot.getDiameter >> (),paint); >> </code> >> >> Now i want all the Dots to listen to a certain event, lets say that i >> want to click a button and move all the Dots. >> What i do is in the Dot constructor i add this code: >> <code> >> IntentFilter intentFilter = new IntentFilter >> ("org.dadata.demo.SEND_TO_REACTOR"); >> Appcontext.registerReceiver(this, intentFilter); >> ....... >> @Override >> public void onReceive(Context context, Intent intent) { >> this.x += 5; >> } >> </code> >> >> Then from my button i send the intent : >> >> <code> >> intent.setAction("org.dadata.demo.SEND_TO_REACTOR"); >> getApplicationContext().sendBroadcast(intent); >> View.invalidate(); >> </code> >> >> I am wondering if someone could give me some feedback on this. Is it >> expensive for instance, and are there better ways to achive the same. >> >> Thank you, >> >> Jiri > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---