Is there a design pattern for this?

I'm looking for a solution to a design problem I have.
For a restaurant booking system I need a number of different opening times describing when you can and cannot book. These opening times are essentially Jodatime Period objects. There's a set of opening times spanning a week and these are repeated for every week (a default set of opening times) however it's possible to override these opening times say for a specific day.
The domain model would be something like a Restaurant class holding 2 Lists of OpeningTime objects one for defaultOpeningTimes and the other for overiddenOpeningTimes the overidden ones get used if they exist for the requested time period. However the database model would be a bit messy as I'd have 2 lists mapping to the same table (OpeningTime). Is that a good idea? Perhaps there's a design pattern for this, if someone could point me in the right direction I'd be very grateful, or perhaps this is the best solution? Thanks!

jduprez wrote:
But why do you put the logic in the database too (I'm no DB expert and I didn't know these concepts until I read your post, but that's what a dynamic view based on derived values looks like to me): performance (1 round-trip instead of two)?Hi jduprez. Long time no speakee.
I guess part of it is that I spent many years as a DBA and modeller, and really appreciate what it's taught me about design. Also, databases are (or should be) designed from the ground up to provide data-directed requests optimally, and include all sorts of nice stuff like transaction handling that aid consistency, as well as speed.
That said: I HATE SQL. Think Coliseum, with that emblazoned in 60-foot high letters around its walls, and it might come close to just how much I hate that so-called "language". I hate its form; I hate it's inconsistencies; I hate the fact that something like what OP is trying to do is NOT an easy task (and might involve the creation of a table that simply contains Dates, just in order to satisfy Boolean logic).
However, once you work it out, a database view (at least from the database's standpoint; JDBC I'm not so sure about) is just like any other Table - and that I DO like.
Programs are good at processing parameterized (ugh) temporal information; databases are good at persistence and high volume. Those two may meet at some point, but I reckon it's going to take another Codd (or Joda) before it does.
- that's clearer to 90% of the dev team (my biased numbers, based on 50% of Java developers having decent knowledge of SQL and much less than that having the advanced SQL knowledge which I rank your suggestion at)Sounds to me like you'll get the solution that matches the skills you have then. Is that what you really want, if a better one is available?
- that doesn't require investigating the if of your suggestion (JDBC support)Agreed, but only because my JDBC knowledge isn't what it could be. I'd also be surprised if it doesn't support access to a named view, since they were designed to be equivalent to Tables.
- the Op is using DAOs, so it's possible, if profiling does show this is hampering performances, to change that with no impact on the client code that calls the DAO.There's no doubt that a database solution is much higher level than a programming one; but, as I said, it's what they were designed to do. And tinkering around with program optimization has the feel of a "hacker's solution" to me. Not that there's any particular problem with that - I do it quite often when I have no control over my source - but I also try to keep in mind what the "actual" problem is.
Winston

Similar Messages

  • Is there a design pattern for this situation?

    Hi,
    I'm making a survey engine. There is a Question class and a bunch of children of it (dropdown, checkbox, textbox, etc.). Now, correct me if i'm wrong, but I feel that this is a good case for inheritance. The problem I have is that Question needs to be initialized with parameters that the concrete question types have no business knowing about:
    //question constructor
    public Question(parameter1, parameter2, parameter3) {...}
    As a result, I am forced to require this as a parameter for all the concrete types since the Question requires these to be initialized:
    //checkbox constructor
    public Checkbox(parameterForQuestion1, parameterForQuestion2, parameterForQuestion3, parameterForMe1, parameterForMe2) {...}
    The checkbox doesn't directly use the first 3 parameters and I'd often prefer the the checkbox object doesn't have access to them. Because of this, i suspect a bad smell. Has anyone ever ran into this problem themselves? How did you solve it?
    Thanks,
    Dan

    tieTYT wrote:
    Yes, there's a bad smell, and it's coming from your proposed design.
    Separate the UI from your Survey and Question objects. Design the model and worry about the UI later.
    %You're assuming I didn't. Just because I'm using the word Checkbox and Dropdown doesn't mean I'm talking about UI components.I hope you didn't. If you actually did some analysis and came up with names like that for non-UI objects, your design is even smellier than I first thought
    A Checkbox has state like, "is box on right?" and "is checked". The Dropdown has state like, "currently selected option" and "list of options". The Question has state like, "am i invisible?", "what is my script", "am i enabled?". None of these classes have UI code in them. They just have names like this because, as you can see, there are fundamental differences between different question types that I use concrete children to sort out. With this setup I've already made a SWING and an AJAX frontend so I must be doing something right in the MVC department. No. I disagree that questions have states like "am I invisible?". That is irrelevant. A Question should not be aware that it is visible. Your design is very poor, I'm afraid, and it works by coincidence
    I'm making the assumption that you thought I wasn't doing this but if you still think this is a bad design, let me know. If not, please help me with my original question.It is, most definately, a bad design. Classes named for UI widgets, but that are not UI widgets? Terrible idea. Really, sickeningly awful. No offence.
    EDIT: And keep in mind this is a SURVEY engine. I specifically want to give the user of the library the power to specify whether their question is a Checkbox/Dropdown/RadioButtons/etc. In a normal application's code, the model wouldn't concern itself with details like, "Is this data going to be visualized as a checkbox?" But I feel that in this situation, the answer to that question actually does belong in the Model. But again, correct me if I'm wrong.
    Edited by: tieTYT on Oct 22, 2007 10:53 AMThe model should be entirely unaware of how it will be rendered. Siure, in this instance, you've decided to render a question as,say, a checkbox. What if you're generating a report on what questions there are? Presentation logic doesn't belong in the model, at all. You say "in a normal application" here, but, like it or not, this is a normal application. Everyone goes through a phase of thinking their own code is special, and different, and new, but it isn't. It's a pretty straightforward app as far as I can tell.
    Re-think your design. A class called Checkbox, that isn't a widget, stinks. Group UI concepts together, and use that as an abstraction. Dropdowns and radio buttons both present questions that can have exactly one correct answer out of a set. So you have a "MultipleChoice" question type. Then, in the UI layer, the decision can be made to render that question as a Dropdown or a bunch of radio buttons, without having to pollute your model with that.

  • What is the best design pattern for this problem?

    No code to go with the question. I am trying to settle on the best design pattern for the problem before I code. I want to use an Object Oriented approach.
    I have included a basic UML diagram of what I was thinking so far. 
    Stated simply, I have three devices; Module, Wired Modem, and Wireless Modem.
    In the Device Under Test parent class, I have put the attributes that are variable from device to device, but common to all of them.
    In the child classes, I have put the attributes that are not variable to each copy of that device. The attributes are common across device types. I was planning to use controls in the class definition that have the data set to a default value, since it doesn't change for each serial number of that device. For example, a Module will always have a Device Type ID of 1. These values are used to query the database.
    An example query would be [DHR].[GetDeviceActiveVersions] '39288', 1, '4/26/2012 12:18:52 PM'
    The '1' is the device type ID, the 39288 is the serial number, and the return would be "A000" or "S002", for example.
    So, I would be pulling the Serial Number and Device Type ID from the Device Under Test parent and child, and passing them to the Database using a SQL string stored in the control of the Active Versions child class of Database.
    The overall idea is that the same data is used to send multiple queries to the database and receiving back various data that I then evaluate for pass of fail, and for date order.
    What I can't settle on is the approach. Should it be a Strategy pattern, A Chain of Command pattern, a Decorator pattern or something else. 
    Ideas?

    elrathia wrote:
    Hi Ben,
    I haven't much idea of how override works and when you would use it and why. I'm the newest of the new here. 
    Good. At least you will not be smaking with a OPPer dOOPer hammer if I make some gramatical mistake.
    You may want to look at this thread in the BreakPoint where i trie to help Cory get a handle on Dynamic Dispatching with an example of two classes that inherit from a common parent and invoke Over-ride VIs to do the same thing but with wildly varying results.
    The example uses a Class of "Numeric"  and a sibling class "Text" and the both implement an Add method.
    It is dirt simple and Cory did a decent job of explaining it.
    It just be the motivation you are looking for.
    have fun!
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • Is there a design pattern for splitting up files into smaller files?

    I am developing a project where I have to load very large files (upto 50 MB). Currently I am loading these files completely into (consecutive) memory. This has the advantage that I can very easily change bytes at certain locations, because I do not know the
    structure of all bytes.
    However, my intention is to also change the structure, e.g. removing/adding 'chunks'. Now I have the idea to remove the 'known' parts out of it, store them in classes with a data chunk only containing those parts and make a sort of reference list to those chunks.
    E.g.:
    Original file:
    Header
    ChunkA 1
    ChunkA 2
    Intermediate
    ChunkB 1
    Footer
    The result will be:
    ChunkA 1 and ChunkA 2 instance. ChunkB 1 instance
    'File' instance and a reference with base offsets + reference to all chunks.
    At the end I have to 'recreate' or write the original file (with changes) back.
    Is this in general a good idea or is there some design pattern helping me in this?

    50MB is not much in the modern era of 6GB+ machines. If you want to optimize memory then consider using a
    memory mapped file.
    But you mentioned making data structure changes. This is generally dangerous as you have to be concerned about things like disaster recovery. What happens if you are in the middle of saving the modified structure when the program dies? You just corrupted
    your file. A better solution is to stream the existing file using BinaryReader to read in the existing file in parts based upon the structure.  Write out the data to a new, temporary file using BinaryWriter. This may be the original data or your modifications
    depending upon need.  Once you've generated the new file replace the old file (with optional backup). So even if something catastrophic happens during saving you don't lose the original file.
    Michael Taylor
    http://blogs.msmvps.com/p3net

  • Choice of design pattern for data acquisition system

    Hello all
    I have a trouble about selecting the suitable design pattern / architecture for a data acquisition system. 
    Here is the details of the desired system:
    There is data acquisition hardware and I need to use it by observing parameters on User interface. 
    the data acquisiton period, channel list to scan should be chosen on User interface. Besides, there are many user interface interactions. e.g. if user selects a channel to add scanlist, then I need to enable and make visible some other parts on user interface. 
    When user completes the channel selection, then he will press the button to start data acquisition. Then I also need to show the scanned values on a graph in real time and log them in txt file.
    I know that I cannot use producer consumer pattern here. because the data acquisition loop should wait for parameters to scan channels. and it works in a given period by user. so the user interface loop performs higher rate then consumer loop (data acquisition loop). it means queue will be bigger bigger. if I use notifier it will loss some data come from user interface. 
    is there any idea about that ? is there any suitable design pattern for this case ? 
    Thanks in advance
    best regards 
    Veli BAYAR
    Embedded Systems Software and Hardware Engineer 
    "You live in a graphical world. Why not program in one?"
    Solved!
    Go to Solution.

    johnsold wrote:
    Veli,
    I recommend the Producer/Consumer model with some modifications.
    You might need three loops.  I cannot tell for sure from your brief description.
    The User Interface loop responds to the user inputs for configuration and start/stop of acquisition.  The parameters and commands are passed to the Data Acquisition loop via a queue. In this loop is a state machine which has Idle, Configuration, Acquisition, and Shutdown states (and perhaps others). The data is sent to the Processing loop via a different queue. The Processing loop performs any data processing, displays the data to the user, and saves it to file. A notifier can be used to send the Stop or shutdown command from the User Interface loop to the other loops.  If the amount of processing is minimal and the file write times are not too long, the Processing loop functions might be able to occur in the Timeout case of the UI loop Event structure.  This simplifies things somewhat but is not as flexible when changes need to be made.
    I am not sure that a Design Pattern for this exact setup exists but it is basically a combination of the Producer/Consumer (Events) and Producer/Consumer (Data) Design Patterns.
    Lynn
    Check out this thread: http://forums.ni.com/t5/LabVIEW/Multiple-poll-case-structures-to-event-help/td-p/2551309
    There are discussions there about a 3-loop architecture that may help you.
    Jeff
    Jeffrey Zola

  • In OBIEE mobile apps designer there is no option for multi select prompts?The navigation page gives option only for single select?Is there a work around for this?

    In OBIEE mobile apps designer there is no option for multi select prompts?The navigation page gives option only for single select?Is there a work around for this?

    Nic, for me the iTunes window looks like this, when I connect my iPad 3:
    I select the iPad in the "devices" section of the Sidebar (use: "View > Show Sidebar" if the sidebar is hidden).
    Click the "Apps" tab in the "Devices" pane.
    Scroll all the way down in the Devices pane to "File Sharing" "Apps" section.
    Then do I click "GarageBand" to select the documents in the right panel.
    Which part is different for you? Perhaps you could post a screenshot?
    Regards
    Léonie

  • What is the best design pattern for multiple instrument​s?

    I have several PXI cards (DMM, O-scope, etc) that I want to create a master panel that can control all of the instruments individually, though not necessarily all at the same time (turn "instruments" on and off at will while the master vi continues to run).  Is there one design pattern (master/slave, producer/consumer, etc.) that works better than another for this type of master panel?  Are there other alternatives for this type of problem (VI Server, etc)?
    I was hoping that I could save a bunch of time if I could start on the right path right off the bat!
    Thanks,
    -Warren

    elrathia wrote:
    Hi Ben,
    I haven't much idea of how override works and when you would use it and why. I'm the newest of the new here. 
    Good. At least you will not be smaking with a OPPer dOOPer hammer if I make some gramatical mistake.
    You may want to look at this thread in the BreakPoint where i trie to help Cory get a handle on Dynamic Dispatching with an example of two classes that inherit from a common parent and invoke Over-ride VIs to do the same thing but with wildly varying results.
    The example uses a Class of "Numeric"  and a sibling class "Text" and the both implement an Add method.
    It is dirt simple and Cory did a decent job of explaining it.
    It just be the motivation you are looking for.
    have fun!
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • Please suggest me a suitable design pattern for the scenario below

    Hello,
    I have around three to four methods in a class. And their invocation is mutually exclusive that only one of them can be called depending upon the scenario. usually to acheive this, what we do is, write if and else loops and depending upon the scenario, we call the method correspondingly. i thought of avoiding this if else loops and would like to know whether there is any possibility for achieving the same without if else loops? if yes how do we do this? is there any design pattern available?
    Thanks, Aravinth

    Hi,
    In java we have something is called reflection; reflection is very powerful API. I would suggest the below to start with
    public class Foo {
         public static final String METHOD_ONE="methodOne";
         public static final String METHOD_TWO="methodTwo";
         public void methodOne() {
              System.out.println("method one is being invoked..");
         public void methodTwo() {
              System.out.println("method two is being invoked..");
         public void methodInvoker(String scenario) throws Exception {
              Class clazz =this.getClass();     
              Method method =clazz.getMethod(scenario, new Class[]{} );
              method.invoke(this, new Object[]{});
         public static void main(String args[] ) throws Exception  {
              Foo foo = new Foo();
              foo.methodInvoker(Foo.METHOD_ONE);
              foo.methodInvoker(Foo.METHOD_TWO);
         }I hope this could help
    Regards,
    Alan Mehio

  • Design pattern for quiz module

    Hello fellow developers.
    I am making/refactoring a module in a jee mobileplatform. It's a quiz module where the enduser participates via sms. Now, I am trying to redesign the module and I am thinking about using the state pattern for this, where the user can be in i.e the following states: StartQuizState(welcomemessage and first question), NextQuestionState, NoAnswerState(the user sent an empty or no valid response), QuizFinishedState(sum up the points etc), and maybe a BonusState if the user makes x points within a specific time limit.
    I was wondering if anyone had any comments on my choice of pattern for this module :)
    Thanks in advance for any comments,
    Best regards,
    Eivind

    Good morning Saish, sorry for my late response.
    First of all - thanks again for showing such interest in my "discussion", and my deepest apologies for my grammatical error hehe, I was tired and wrote a little bit too fast. Normally I take great pride in writing correctly :)
    I would also like to say that many, many times before, these forums, and others, have helped me when stuck in a programming problem or other problems related to software. So without all those people out there willing to spend their free time answering questions from people like me, a lot of us wouldn't be able to solve whatever problem we might have, and basically the general experience amongst inexperienced programmers would evolve much slower. So Saish, thanks to people like you there are a lot of happy programmers out there. It is very important for those of us working with development, to share whatever knowledge we might have.
    Anyway back to the discussion:)
    I totally agree, the state is absolutely the Quiz, not the contestant of the quiz. I just read a Head first design patterns (a great book by the way!), and I was a bit to hung up on using patterns instead of looking for a solution that works. So what I have done so far, refactoring my solution:
    I have the following models:
    - Quiz
    - Contestant
    - Answer
    - QuizManager
    Quiz Object
    The Quiz model that represents the actual quiz, which contains a list of Question objects, and Answer objects. The quiz has a int constant QUIZ_STATE, and the possible states:
    private static final int START_QUIZ_STATE = 0;
    private static final int FINISH_QUIZ_STATE = 1;
    private static final int NEXT_QUESTION_STATE = 2;
    private static final int REPEAT_QUESTION_STATE = 3;
    private int quizState = START_QUIZ_STATE;
    As you can see the quizState defaults to START_QUIZ_STATE. The first thing I do when the contestant enters, is to check the state of the quiz, if he already is an contestant, if the quiz is finished etc.
    Then I continue and process the quiz based on the state of the quiz (this time everything in one class - a quizmanager).
    Contestant Object
    Contestant model containing what questions are already answered, number of points and so on.
    Answer Object
    The Answer object is created if the contestant sends an answer and his answer corresponds with the alternatives in the Answer object. E.g if the answer alternatives are a) 100 kilometers and b) 20 kilometers, and the contestant sends an answer c, it is considered as no answer, and the last question is repeated, if the contestant sends a, or b, his answered is compared with the current Answer alternative, and a new question is sent him.
    I have some database tables for managing this module, and basically a Quiz is configured as an XML, where 1 xml is a quiz, and 1 quiz xml can contain many question and answer tags. These are read upon quiz start, and Quiz, Answer, and Question objects are created. Every time a new contestant enters, a new Contestant object is ofcoursed created.
    All the logic takes place in the previously mentioned QuizManager. Any comments on the solution so far would be greatly appreciated.
    If interesting to anyone I can post the classes when I am finished with the module, as a standalone java application without a database.
    Regards,
    Eivind

  • Design Pattern for execution queue

    Anyone know of any good design patterns for using a JMS Queue and MDB's
              as async
              execution queue which maintains execution order by some key
              

    Enforced ordering on redelivery will be supported in the
              next release, but only if the application clamps the pipe-line
              size down to its minimum and the MDB pool size down to one.
              I don't think enforced ordering is supported in the current release.
              We are looking at least partially addressing the general design
              pattern below in the release after next. I don't think I can
              get away with being more specific. (Sorry.) Currently, I
              think something along the line of Larry's solution is the only way to
              accomplish it. Interestingly, the recent thread started
              by "[email protected]" on correlating requests and responses
              seems to be somewhat related.
              Tom, BEA
              Larry Presswood wrote:
              > Well you are both correct however we have something which works
              > however it does involve some threading primitives which generally is not
              > a good idea
              > inside wlas but seems to work.
              >
              >
              > Generally have a singleton on the server which has slots for each key
              > with message
              > numbering for each message and force a wait if message for key is out of
              > order
              > during fifo processing rules. IE do what things you can do in parallel
              > but gate for
              > the last step.
              >
              > I think there is a general remote execution pattern out there.
              >
              > The general problem to solve is this:
              >
              > In a messaging system you want to process messages for each key/session
              > in order however
              > with a large number of sessions its possible to parallel messages for
              > different sessions
              >
              > Otherewise you can either create custom queues or a topic with a
              > selector and then
              > create custom consumers which does not behave as well from a resource
              > perspective
              > as MDB's do.
              >
              >
              >
              >
              >
              >
              >
              > Nick Minutello wrote:
              >
              >>I may be completely wrong - but I think that Larry is referring to the inherant
              >>out-of-order message consumption that you get when using MDB pools to consume
              >>from a Queue.
              >>
              >>In short, the only design pattern here is to deploy the MDB to only one machine
              >>in the cluster - and set the pool size to 1.
              >>
              >>In-order execution is incompatible with the parallel execution that MDB's give
              >>you.
              >>
              >>-Nick
              >>
              >>
              >>
              >>Tom Barnes <[email protected]> wrote:
              >>
              >>
              >>>Hi Larry,
              >>>
              >>>Generally, I think it is best to have a seperate queue per key if the
              >>>
              >>>number of keys is small. This prevents starvation of a particular
              >>>message. For example when handling message-priority, low priority gets
              >>>
              >>>an MDB pool of size 1, high priority gets and MDB pool of size 10.
              >>>
              >>>Note that WebLogic JMS allows a queue to specify a sort-order keys based
              >>>on arbitrary message fields. Note that the in-flight message pipe-line
              >>>
              >>>between server and asynchronous clients is unsorted.
              >>>
              >>>Tom, BEA
              >>>
              >>>Larry Presswood wrote:
              >>>
              >>>
              >>>>Anyone know of any good design patterns for using a JMS Queue and MDB's
              >>>>
              >>>>
              >>>>as async
              >>>>execution queue which maintains execution order by some key
              >>>>
              >>>>
              >>>>
              >>
              >>
              >>
              >
              

  • Design pattern for display configurable UI

    Hi,
    We have a UI requirement where a form (page) needs to display different components based on where the form is being accessed from.
    For e.g. If the form "X" is accessed from "abc" form then it has to display a dropdown and a list box. If the same form "X" is accessed from "xyz" form then it has to display one more dropdown in addition, along with the list box.
    The validations to be done on "X" form also depend on from where it accessed from.
    Can someone please guide on how should the form be designed (e.g. how should the input parameters be taken etc)? Is there any design pattern already in place which I can refer to?
    Thanks in advance.

    Can't think of a pattern for this, merely, several patterns to deal with smaller concerns, such as "differentiate behavious based on the current state or on a parameter".
    I would point out that you probably shouldn't design each form to depend on where it is called from, but merely on what parameter it is called with. For example (assuming your foms are JSPs in a Web application), you can pass a parameter in the URL, but it would be awkward that the parameter be "origin=xyz", instead it should be "detailedOption=true". That seems more evolutive, so that if you ever need the second drop down to be displayed when the form is called from another page "efg", you don't have to modify the form.
    Now if you are worried that page "abc" and "xyz" have to know that they have to call (hyperlink to, or forward to) X which the correct value of "detailedOption", you can still have them call dedicated pages "XafterAbc" and "XafterXyz", and let your URL mapping, or dedicated controller code, map "XafterAbc" to "X?detailedOption=false".
    J.

  • Design pattern for several conditions

    Hi;
    I would like to implement an search algorithm which use many conditions (search criteria).
    For Example
    Begin :
    If criteria A && B are OK => if criteria C is OK => etc...
    Else criteria D && F are OK => if criteria C is OK => etc...
    Else etc...
    which design pattern or another design correspond to my requirement ?
    Regards;

    You are missing the point somewhere. Object-oriented design patterns are tools used to design object-oriented applications. There is a certain limit to size that is associated with warranted usage.
    In other words, the issue of your post is a trivial element of conditional processing. There is no such design pattern to apply to such a thing because that is not what design patterns are used for.
    Aside, some forum "genius" is going to post some application of a design pattern to this issue and then call me crazy. Looking forward to it :o)
    Your question would be better suited if it asked for what type of conditional processing algorithm might work well. In Java there are a few to work with. If statement, do while statement , while statement, case, etc.

  • Design Pattern for Asynchronized Communication

    I've got to implement a special protocol for network communication:
    1. You'll have one connection, in this case, a TCP or UDP socket, all messages are exchanged via it.
    2. You have multiple threads sending requests and receiving response concurrently using the same socket:
    a. Each thread use a logic channel, which, from the thread's perspective, is an independant channel, the thread won't receive messages for other channels.
    b. Each request/response is a packet that can be treated as atomic - you either send/receive it in one go or not at all. Each packet has the channel id, so you know which channel it belongs to.
    c. For each thread, it sends request then waits for response, and then sends the next request and so on.
    Hope the senario is clear.
    So, some kind of notification pattern should be used here, I guess?
    OK, check my pattern books, all of them are talking about callback stuff like listener, observer etc, however, they don't fit in this scenario, as each thread use their channel like a socket without knowing any details of underlying connections, their codes would be like:
       sendRequest(req);
       Response res = receiveResponse();The receiveResponse() needs to be a block call, so the only solution here is a wait()/notify() pair (this all I can come up with, you are welcome to suggest other pattern). So, a lot of synchronization would be going on, e.g., if the receiving thread (a dedicated thread that reads all messages from the underlying socket) notify the thread before it enter wait() status in receiveResponse() would result in serious bug.
    I just wonder if there is a good pattern for this scenario? (I didn't read lots of design book, so may not be aware of such pattern). Any input are welcome.

    Sounds like you've laid out your problem quite well.
    You could use a fifo queue (producer-consumer queue) per thread - basically receiveResponse would check to see if there is anything in its (response) queue - if so, it is removed, if not, it waits. The socket thread receives a packet, finds the appropriate queue and pushes in the response - which wakes the receiver. This is thread safe, if done correctly - it is easy to do correctly.
    Now that I think about it more, your queue can only store one element, given the request/response nature of the communication, so you don't even need to use a collection.
    As for patterns, I think that Pattern Oriented Software Architecture Volume 2 (http://www.cs.wustl.edu/~schmidt/POSA/) may be of interest. And if threading and concurrency are of interest, checkout Concurrent Programming in Java, Doug Lea (http://www.amazon.com/exec/obidos/ASIN/0201310090/)

  • Design pattern for unprotecting and reprotecting sheets with VBA?

    Many macros can't run when a worksheet is protected, so when I develop an Excel workbook that has protected worksheets, I have to unprotect worksheets when macros are called and then reprotect the worksheets once the macro has completed.
    The current design pattern I use for this is the following:
    I look at each procedure individually and consider which sheets need to be unprotected for it to run. Then in each procedure I write:
    Sub Test()
    Dim bSheet1Protected as boolean
    Dim bSheet2Protected as boolean
    bSheet1Protected = Sheet1.ProtectContents
    bSheet2Protected = Sheet1.ProtectContents
    bSheet1Protected.Unprotect
    bSheet2Protected.Unprotect
    '''The rest of my code
    if bSheet1Protected then Sheet1.Protect
    if bSheet2Protected then Sheet2.Protect
    End Sub
    But I imagine that maybe there are better ways of doing this. What is your preferred design pattern for unprotecting and reprotecting sheets with VBA?

    Hi JP3O,
    I think it is a good practice to unprotect the worksheet before execute some code and protect it back after the code execute finished.
    >>But I imagine that maybe there are better ways of doing this. What is your preferred design pattern for unprotecting and reprotecting sheets with VBA?<<
    I am not able to find a better way since we always need to unproect the worksheet if some code didn't not executed successful when the worksheet is proected.
    Regards & Fei
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Design Pattern for Controlling Uniqueness

    Hi,
    I'm looking for a good design pattern for controlling uniqueness. E.g. I have classes representig a particular database relation. The constructor has the database key(s) as parameter(s). For the other attributes there are corresponding setter and getter methods.
    How can I make sure, that I have only one instance with key(s) foo in my system?
    Of course I have some ideas but I'm not sure if that is the best thing I could do. So I could use a map, to map the keys to the tuples.
    This map could be in another class foo2 which creates the objects of foo1 (which has only a protected or package-private constructor).
    Or I could place the map into foo1 itself as a static variable, and add a static factory method. The constructors would then be protected or private. Are these solutions good? Which one to prefer?
    How can I handle other unique attributes (not part of the key)?
    The equals method for such a class could then test the keys only, since there is only one object with such a key in the system, right?
    Thanks for any help.
    Greets
    Puce

    The class could have only private constructors and a public static getter method, which would decide based on some collection of the object created so far, whether to create a new one or give an old one.

Maybe you are looking for

  • Music sharing from one itunes account to another itunes account

    My question is I downloaded music from my brother-in-law's itunes account to my iphone, then when I try to sync my iphone to my itunes account it tries to erase the music that was downloaded on my iphone. Is there anyway to download the music to my i

  • How to run servlet program in eclipse 3.1

    i run the jsp program in eclipse 3.1 i want to run sample servlet program in eclipse, how to create the project,where to store the class file..? where to store the web.xml file..? plz give explanation with HelloWorld.java program....

  • 2 ipods on the same iTunes

    Is it possible to have 2 differents ipods , ie a nano and a 30gb video accessing the same itunes library on one profile. Can anyone help before I try and do this. Thanks Derek

  • Forecast is not in the LOV for Plan options

    I created a forecast and have one item in it. It is forecasted with one date. I saved it and go to the plan's options under the organization tab. Under demand schedules I do not see my newly created forecast in LOV. Thanks, Keith

  • Matchcode Object for ORGEH field in Selection-Screen

    Hi,    I need to create a Matchcode Object for ORGEH field in my Selection-Screen. But, I want to have the selection Criteria as the Tcode: Po10 does. Please guide me how to do it. Is there any Standard Matchcode Object provided by SAP for this kind