Design issue: which is better?

In the situation like below
public class Foo{
    public Foo(){
         Foo1 f1 = new Foo1();
         //other code to start the thread
//Foo1 class
public class Foo1(){
     public synchronized void setData(String s){
           //codes that adds the data to a LinkedList
     public synchronized String getData(){
         //codes
//main class
public class MainClass{
    public MainClass(){
         Foo f = new Foo();
    public static void main(String[] args){
         //code to check the size of list before setting the message
          //code to set message here.
}In the above code, i want to check the size of the message list in the Foo1 at the main class before setting the message.
The condition is that i dont want to set the message when a certain value is reached, and start setting the message when the size of message
drops down to certain value.
My problem is: Which option is better: to use the Observer pattern or
to have a method that returns the size of the message?
any suggestions?
thank you for your comments.

My message code list is like
public class Foo1{
    private LinkedList mList = new LinkedList();
    public synchronized void setMessage(String s){
              mList.addLast(s);
    public synchronized String getMessage(){
             return (String)mList.removeFirst();
    }That is what i have in my Foo1 class.
I want to check the size of the list at the main class before adding the
message.
I hope i am clear.

Similar Messages

  • Design Issue,Please reply

    Hi,
    If i want to define a HashMap,i can do it either as
    a) HashMap map = new HashMap() or
    b) Map map = new HashMap()
    From design perspective which is better one and why ?
    Thanks
    vasubabu

    When declaring references as superclasses or interfaces (such as List or Map or whatever), you can change the implementation without braking existing code. I.e. what was previously an ArrayList can be made a LinkedList and you only need to use 1 place in code. If you're not using a superclass reference, you need to change the code in more places.
    It's not always necessary to declare the reference as a superclass one, but when the program might be changed later on and it's not absolutely certain that an ArrayList (for example) will be used, it's better to use List (or Map) as the reference.
    Also Joey, your explanation sucked. There is no advantage in using a HashMap reference in place of a Map reference, apart from seeing the exact type in the places it's used.

  • Which is better for solving Mac issues

    I have been experiencing Kernel Panics and program crashes. I want something that is good for testing hardware and OS issues. Can either of these find corrupted data files? I am looking at two utilities for purchase. Which is better for solving Mac Issues?
    TechTool Pro
    or
    Disk Warrior?

    When you say "complete bootable backup" do you mean that it contains the OS + all my applications? Basically a clone of the start-up?
    Yes, you have that very clear. I use Tri-backup or CCC for this normally, but there are other options.
    If I have this clone, and I start getting issues on my Mac, I can Zero the HD and reinstall the OS via the clone (including all the applications)?
    Yes, and if pressed for time you can just keep working off the Clone.
    I can Zero the HD and reinstall the OS via the clone (including all the applications)?
    Yep, right back to 100%, excluding HW issues.
    With all my software... it takes a day to reinstall all of it to a complete image.
    Yes, the only sensible thing is a Clone... or two. Most problems can be overcome by simply Verifying/Repairing the HD once in awhile, Repairing Permissions before and after every update/upgrade, and turning off Auto Updates in SW Update CP... wait a couple of weeks and check these forums for the number of problems with any update.
    PS. DiskWarrior has saved me hundreds of times from having to do complete new Installs or cloning back of Installs, I figure that's saved me 10's of thousands of hours & grief... I appreciate Alsoft so much that I don't even go for the generous upgrade offers on new versions... I just buy the new version completely at Retail.
    PPS. Funny thing, you'll read something like DiskWarrior is a one Pony Dog Show or something... just does one thing... I just have to laugh outloud... Yeah, the one thing is... cure my incurable Mac Problems 99.9% of the time!

  • Which is better for solving Mac G5 issues

    I have been experiencing Kernel Panics and program crashes. I want something that is good for testing hardware and OS issues. Can either of these find corrupted data files? I am looking at two utilities for purchase. Which is better for solving Mac Issues?
    TechTool Pro
    or
    Disk Warrior?

    Hi! Both and neither. Diskwarrior is the undisputed king of disk drive directory repair (which is the leading cause of drive problems)but that's all it does. TTP does directory repair although not as good as DW but TTP has a hardware test suite to test the components and can test a disk for bad blocks. I recommend both although you'll find yourself using DW the most. If you bought your machine new you should have a hardware test disk. It could be a separate disk or on one of the restore disks. As for your KP's start by disconnecting everything except the keyboard and mouse. Ram is also a likely culprit as can be a video card. The console log file will often give you a hint of the offending item. DR SMOKES article on KP's will also help. Tom

  • Design Issue: Localization using Lookup OR Dependency Injection

    Hello Forums!
    I'm having a design issue regarding localization in my application. I'm using Spring Framework (www.springframework.org) as an
    application container, which provides DI (dependency injection) - but the issue is not Spring- but rather design related. All localization
    logic is encapsulated in a separate class ("I18nManager"), which basically is just a wrapper around multiple Java ResourceBundles.
    Right now localization is performed in the "traditional" look-up style, e.g.
    ApplicationContext.getMessage("some.message.key");
    where ApplicationContext is a wrapper around the Spring application context and getMessage(...) is a static method on that
    context. The advantage of that solution is a clean & simple interface design, localization merely becomes a feature of classes, but
    is not part of their public API. The only problem with that approach is the very tight coupling of Classes to the ApplicationContext, which
    really is a problem when you want to use code outside of an application context. The importance of this problem increases if one considers
    that I18N is a concern that can be found in every application layer, from GUI to business to data tier, all those components suddenly depdend
    on an application context being present.
    My proposed solution to this problem is a "Localizable" interface, which may provide mutators for an "I18NManager" instance that can be
    passed in. But is this really a well-designed solution, as almost any object in an application may be required to implement this interface?
    I'm too concerned about performance: the look-up solution does not need to pass references to localizable objects, whereas my proposed solution
    will require 1 I18NManager reference per localizable object, which might cause troubles if you let's say load 10.000 POJOs from some database that
    are all localizable.
    So (finally) my question: how do you handle such design issues? Are there any other solutions out there that I'm not aware of yet? Comments/Help welcome!

    michael_schmid wrote:
    Hello Forums!
    I'm having a design issue regarding localization in my application. I'm using Spring Framework (www.springframework.org) as an
    application container, which provides DI (dependency injection) - but the issue is not Spring- but rather design related. All localization
    logic is encapsulated in a separate class ("I18nManager"), which basically is just a wrapper around multiple Java ResourceBundles.Why do you think you need a wrapper around resource bundles? Spring does very well with I18N, as well as Java does. What improvement do you think you bring?
    Right now localization is performed in the "traditional" look-up style, e.g.
    ApplicationContext.getMessage("some.message.key");
    where ApplicationContext is a wrapper around the Spring application context and getMessage(...) is a static method on that
    context. Now you're wrapping the Spring app context? Oh, brother. Sounds mad to me.
    The advantage of that solution is a clean & simple interface design, localization merely becomes a feature of classes, but
    is not part of their public API. The only problem with that approach is the very tight coupling of Classes to the ApplicationContext, which
    really is a problem when you want to use code outside of an application context. The importance of this problem increases if one considers
    that I18N is a concern that can be found in every application layer, from GUI to business to data tier, all those components suddenly depdend
    on an application context being present.One man's "tight coupling" is another person's dependency.
    I agree that overly tight coupling can be a problem, but sometimes a dependency just can't be helped. They aren't all bad. The only class with no dependencies calls no one and is called by no one. We'd call that a big, fat main class. What good is that?
    Personally, I would discourage you from wrapping Spring too much. I doubt that you're improving your life. Better to use Spring straight, the way it was intended. I find that they're much better designers than I am.
    My proposed solution to this problem is a "Localizable" interface, which may provide mutators for an "I18NManager" instance that can be
    passed in. But is this really a well-designed solution, as almost any object in an application may be required to implement this interface?I would say no.
    I'm too concerned about performance: the look-up solution does not need to pass references to localizable objects, whereas my proposed solution
    will require 1 I18NManager reference per localizable object, which might cause troubles if you let's say load 10.000 POJOs from some database that
    are all localizable.
    So (finally) my question: how do you handle such design issues? Are there any other solutions out there that I'm not aware of yet? Comments/Help welcome!I would use the features that are built into Spring and Java until I ran into a problem. It seems to me that you're wrapping your way into a problem and making things more complex than they need to be.
    %

  • Data mart from two DSOs to one - Loosing values - Design issue

    Dear BW experts,
    I´m dealing with a design issue for which I would really appreciate any help and suggestions.
    I will be as briefly as possible, and explain further based on the doubts , questions I received in order to make it easier go through this problem.
    I have two standard DSOs (DSO #1 and #2) feeding a third DSO (DSO #3), also standard.
    Each transformation DOES NOT include all fields, but only some of them.
    One of the source DSO (let´s call it DSO #1) is uploaded with a datasource that allows reverse type of records  (Record Mode = 'R'). Therefore some updates on DSO #1 comes with one entry with record mode 'R' and a 2nd entry with record mode = 'N' (new).
    Both feeds are delta mode, and not the same entries are updated through each of them, but the entries that are updated can differ (means an specific entry (unique key values)  could be update by one of the feeds, but no updates on the 2nd feed for that entry).
    Issue we have:  When a 'R' and 'N' entries happen in DSO #1 for any entry, that entry is also reversed and re created in the target DSO #3 (even being that not ALL fields are mapped in the transformation), and thefore we loose ALL the values that are exclusively updated through DSO #2, becoming blank.
    I don´t know it we are missing something in our design, or how should we fix this issue we have.
    Hope I was more or less clear with the description.
    ´d really appreciatted your feedback.
    Thanks!!
    Gustavo

    Hi Gustavo
    Two things I need to know.
    1. Do you have any End Routine in your DSO? If yes, what is the setting under "Update behavior of End Routine Display"....Option available right side of Delete Button ater End Rouine.
    2. Did you try with Full Load from DSO1 and DSO2 to DSO3? Do you face the same problem?
    Regards
    Anindya

  • Design issue with sharing LV2 style global between run-time executables

    Hi,
    Just when I though that I had everything figured out, I ran into this design issue.
    The application that I wrote is pretty much a client-server application where the server publishes data and the client subscribes data using data sockets. Once the client gets all the data in the mainClient.vi program, I use LV2 style (using shift registers) to make the data global to all the other sub-vi’s. So the LV2 is in initialize mode in the mainClient.vi program and then in the sub-vi’s the LV2 is in read mode. Also, I had built the run time menu for each sub-vi that when an item is selected from the menu, I would use the get menu selection to get the item tag which will be the file nam
    e of the sub-vi and open the selected sub-vi using vi server. This all worked great on my workstation where I have labVIEW 7.0 Express installed. But the final goal is to make exe’s for each of these sub-vi’s and install runtime on the PC’s that do not have labVIEW installed. Of course when I did that only the mainClient.exe program was getting the updated data from the server but the sub-vi’s were not getting the data from the mainClient.exe. I did realize that the reason for this is due to the fact that I had compiled all the sub-vi’s separately and so the LV2 vi is now local to each executable (i.e. all executables have their own memory location). Also, the run-time menu did not work because now I am trying to open an executable using vi server properties.
    To summarize, is there a way to share LV2 style global's between executables without compiling all of the sub-vi’s at one time? I tried using data-sockets (local-host) instead of LV2 st
    yle gloabls to communicate between the sub-vi’s but I ran into performance issues due to the large volume of data.
    I would really appreciate it if anyone can suggest a solution/alternative to this problem.
    Thanks
    Nish

    > 1)   How would I create a wrap-around for the LV2.vi which is
    > initialized in my mainClient.vi and then how would I use vi server in
    > my sub-vi to refer to that LV2.vi?
    > You mentioned that each sub-vi when opened will first connect to the
    > LV2.vi via via-server and will keep the connection in the shift
    > register of that sub-vi. Does this mean that the sub-vi is accessing
    > (pass-by-reference) the shared memory of the mainClient.vi? If this
    > is what you meant I think that this might work for my application.
    >
    If the LV2 global is loaded statically into your mainClient.vi, then any
    other application can connect to the exe and get a reference to the VI
    using the VI name. This gives you a VI reference you can use to call
    the VI. Ye
    s, the values will be copied between applications. That is
    why you need to add access operations to the global that returns just
    the info needed. If you need the average, do that in the global. If
    you need the array size, do that in the global. Returning the entire
    array shouldn't be a common operation on the LV2 style global anyway.
    > 2) Just to elaborate on my application, the data is
    > transferred via DataSockets from the mainServer.vi on another PC to
    > the client’s PC where the mainClient.vi program subscribes the
    > data (i.e. 5 arrays of double type and each arrays has about 50,000
    > elements). The sub-vi’s will have to access these arrays
    > located on the mainClient.vi every scan. Is there any limitation on
    > referencing the mainClient.vi data via vi-server from each sub-vi?
    Your app does need to watch both the amount of data being passed across
    the network, and the amount being shared between the apps. You might
    want to consider puttin
    g the VIs back into the main app. What is the
    reason you are breaking them apart for?
    Greg McKaskle

  • Which is better for gamming, Macbook Pro 13'' or Macbook Pro 13'' Retina?

    Which is better for gamming, Macbook Pro 13'' or Macbook Pro 13'' Retina?

    LowLuster wrote:
    You are certainly welcome to your opinion. I'll stick to my reply.
    In view of the fact that there are numerous applications that run properly while creating a lot of internal heat in a MBP indicates that it does not follow that heat is an inhibiting factor (within designed parameters).  Thus my comment is certainly not opion, rather fact.  You certainly are entitled to your reply but a third party reader should be be apprised of what the facts are. 
    Ciao.

  • Which is better - Mac book pro or air book ?

    Which is better a Mac book pro or an air book.  What is the pros and cons in using ?? 

    It depends on your preference and how you will use it. Example, if you're a designer, engineer, doing a lot of video editing, sound editing, then you'll appreciate the horsepower the Pro which means "Professional" can offer you. If you're a student, or someone who'll be using primarily for document making or presentation, then the Air would fit you, plus a bonus with the name Air which means "ultra light". The big difference though is the processing speed of the two laptops. The Pro uses full processor speed, while the Air for thermal concerns uses a slightly slower processor. 
    Good Luck picking the one which will suit you

  • Which Is Better For High School, An Air or A Pro?

    Which Is Better?

    SSD drives are superior in many ways and would give the air another +1 of course you can always upgrade.
    if size and budget are of no issue,  MacBook Pro Retina 15" would be invaluable to anyone student or not
    I am using this macbook air:
    1.8GHz Intel Dual-Core Core i5, Turbo Boost up to 2.8GHz
    4GB 1600MHz DDR3L SDRAM
    128GB Flash Storage
    and this macbook pro for my comparison:
    2.5GHz Dual-core Intel Core i5, Turbo Boost up to 3.1GHz
    4GB 1600MHz DDR3 SDRAM — 2x2GB
    500GB Serial ATA Drive @ 5400 rpm
    SuperDrive 8x (DVD±R DL/DVD±RW/CD-RW)

  • Which is better, Netgear N900 or Airport Extreme?

    Which is better, Netgear N900 or Airport Extreme?

    Gpcn,
    I'm going to highly recommend the new Airport Extreme. I've been having all sorts of wifi and networking issues because of the saturated 2.4 GHz spectrum in my surrounding neighborhood.
    I finally bit the bullet on friday night and purchased the Airport Extreme. I could not be happier!
    I used to top out at around 8 Mbit/s download and 1 Mbit/s upload with my older Linksys setup. Now i'm getting 40+ Mbit/s and 2 Mbit/s respectively.
    Not only that, but i'm no longer dropping my wifi with my devices (latops, iPads, iPhone, etc). It's very consistent and the speeds are amazing!
    Sure it may be pricier than others, but it's worth every penny. The setup is very easy and you get Three Gigabit Ethernet LAN ports for connecting computers or network devices as well as built-in NAT support for security. You are better off getting the Airport Extreme.

  • Which is better at 3G

    Which is better 3g? at&t or verison

    "which is better, if, at school, 3G is non existant, and GPS is not an issue as all my cars have navigation?"
    Why not pay a consultant to answer your question then rather than relying on a 'free-bee' <g> or 'freebie' from good folk who sometimes and for some people really can't be bothered to help people when they can't put in the effort to help themselves (being polite and British and all, otherwise I might be prompted to say "I don't give a flying f* for your inability to sort things out for yourself").
    FYI, all apps work on 2.1 that worked on 1.0....
    Good luck (you might need it through life)!

  • Which is Better? Mac or PC?

    Which is Better?
    Intel iMac   Mac OS X (10.4.5)  

    Hello,
    I'm not going to argue that a Mac is better, but I do have a response to:
    looking computers and the software is great however
    they have major compatibility issues. for example
    many websites do not support mac's Ex.
    www.aircanada.com
    I have never had any problem exchanging documents or viewing web pages with the Mac.
    All my document exchanges have worked flawlessly, and work going both to and from Windows PC's.
    But, you need to make sure you are using the right program on the Mac if you want to share files with PC users.
    As for the website compatibility, the site you provided as an example will work just fine. They just don't want you to know it.
    What that website is doing, is running a check to see what web-browser you are using. Beyond that, they are also running a check to see which computer you are using.
    So, what you need to do is make sure that your browser tells their website what it wants to hear.
    So, in Safari, you can use the "Debug" menu to have Safari report itself as the Windows version of Internet Explorer.
    Go to the Debug menu, then pick "User Agent", then choose: "Windows MSIE 6.0".
    If the site still won't load, then go to the site first, and perform the selection again from the Debug menu.
    Basically, what you are doing is changing what Safari identifies itself as.
    Additionally, the website that you listed does list that it is compatible with Mac OS 9.0 or later. So, it should work provided you pass it's checks.
    If for some reason it still won't work, contact them since they say that it is compatible with the Mac.
    The only sites that absolutely will not work with a Mac are sites that use "Active X" to take over control of your computer or communicate directly with the operating system. Fortunately, those sites are getting rarer and rarer.
    The only site I've run across in recent times that uses Active X is Microsoft's Windows Update site (which you wouldn't need with a Mac anyway).
    As for enabling the "Debug" menu in Safari, if it is not already there, you can do that by:
    Closing Safari
    Open "Terminal" which is located at:
    Hard Drive --> Applications --> Utilities --> Terminal
    Then type the following at the command line:
    defaults write com.apple.Safari IncludeDebugMenu 1
    If you would prefer an automated method of enabling the Debug menu, you can always download the free Safari Enhancer program which includes a setting for this feature:
    http://www.lordofthecows.com/softwarelist.php

  • A web service design issue with patterns

    Hello,
    I�d like to ask for your help in the following design issue:
    I need to create an email sending web service (with Axis). Only just one method which returns with an integer return code. This handles the following:
    - based on the given parameters gets the email addresses from an
    LDAP server (with netscape ldap for java)
    -     makes a cache from them (only after a timeout period will be the cache
    refreshed) (don�t know what tool to use for this)
    -     selects html templates which to be sent based on the given parameters
    -     sends emails with the appropriate templates (with Velocity)
    -     the whole process is logged (with log4j)
    I have to write the code as generic as possible. I know that some design pattern should be used for this. (some from GoF , and I know there exists design patterns specially created for web services as well).
    Could you enumerate me which patterns (and for what part of the program) would be the best choice to solve this problem? I have read through some books about patterns, but don�t have the knowledge to pick up the right one for a concrete problem like this..
    Thank you in advance,
    nagybaly

    Hello,
    I�d like to ask for your help in the following design
    issue:
    I need to create an email sending web service (with
    Axis). Only just one method which returns with an
    integer return code. This handles the following:Lots of responsibilities here. You would do well to break this up into several classes that you can test separately.
    I would also advise that you not embed all this in a servlet. Make a service that collaborates with several objects to accomplish the task and let the serlvet just call it.
    .> - based on the given parameters gets the email
    addresses from an
    LDAP server (with netscape ldap for java)I'd recommend Spring's LDAP module. Pretty terrific stuff.
    cache from them (only after a timeout period will be
    the cache
    refreshed) (don�t know what tool to use for
    this)Maybe EhCache or OsCache or something like that.
    -     selects html templates which to be sent based on
    the given parametersWhere does this come from? Certainly not the LDAP. A relational database? Write a DAO for the document template.
    -     sends emails with the appropriate templates (with
    Velocity)Have an e-mail sender service using Java Mail.
    -     the whole process is logged (with log4j)Easily done.
    I have to write the code as generic as possible. I
    know that some design pattern should be used for
    this. No pattern. There might be patterns, if you say that the DAOs to access the LDAP and RDB are patterns.
    Stop thinking patterns and start thinking objects.
    (some from GoF , and I know there exists design
    patterns specially created for web services as
    well).Nope.
    Could you enumerate me which patterns (and for what
    part of the program) would be the best choice to
    solve this problem? I have read through some books
    about patterns, but don�t have the knowledge to pick
    up the right one for a concrete problem like this..
    Thank you in advance,
    nagybalyYou haven't read them because they aren't there. Your problem is pretty specific, even if it's common.
    %

  • Which is better, many PXI cards or fewer PXI cards with more SCXI cards?

    I have a pretty basic question.  Which is "better", using multiple PXI cards for analog inputs or a single PXI card and multiple SCXI cards?  For example, if I have say 100 channels to sample (all at the same rate), I could use 2 6225s at 80 ch each.  Or I could use 1 6220 and 4 SCXI 1100s (32 ch each).  What are the pros and cons with either approach?  Keep in mind sample rate probably isn't an issue (less than 1 kHz) but it is the same for all channels.
    Thanks.

    The pros/cons will depend on your application now and in the future.  I recommend contacting your local NI sales representative.  Synchronizing across a PXI system is easy to do via the backplane.  There are PXI/SCXI combo chassis available, you could use PXI multifunction DAQ cards and then SCC for signal conditioning for thermocouples for additional functionality later.  There are many possibilities that may be best discussed with your sales representative.
    Regards,
    h_baker
    National Instruments
    Applications Engineer
    Digital Multimeter Resources

Maybe you are looking for

  • Derivation Rule In FM

    Hello Sappers Can any body explain derivation rule in FM and what are the steps involved.Actually i want to understand  what is meant by deriving fund center and commitment item. Thanks.

  • Can't open raw files from Nikon d800 in PS CS5 and can't update Camera Raw plug-ins

    Can't open raw files from Nikon d800 in PS CS5 (Win7 64-bit). It says, the model not supported by Camera Raw. Tried updating Camera Raw plug-ins for d800 but keep getting error message: Update failed, Adobe Application Manager may be damaged. Re-inst

  • Download data to excel sheet

    hi all, i have a situation, i want to download the data of an alv grid display to a excel sheet, is there any other way of doin it other than choosing from the List menu, coz when i click the excel sheet button on the application tool bar i get a bla

  • (retain) properties in the singleton class

    Hi, What happens with the properties declared with (retain) in the singleton class: MyClass *foo; @property (nonatomic, retain) MyClass *foo; I am using a singleton class as explained http://developer.apple.com/mac/library/documentation/Cocoa/Concept

  • ITunes is associating files that do not belong- i.e., Internet Explorer and other programs.  How do I fix?

    When I download iTunes, it takes over programs such as Internet Explorer such that when I double-click on the icons for these programs, I'm taken to iTunes as opposed to the program I selected.  Also, my other programs are now associated with the iTu