Builder Design Pattern

Hi,
I'm trying to implement the Abstract Builder design pattern for a fairly complex object. If I understand correctly, the builder creates the whole object in one shot; as in, the pieces are hidden from the client while the object is being built. So suppose the object that I need to include as an "ingredient" is more complex. I have a class called Route (with different types that extend it) that requires a list of segments and an origin and destination. The part I'm confused on is how to build a route if I can't provide parameters for it. All the examples I've found so far have had simple objects for the ingredients that didn't require any personalization. Sorry if I'm being unclear. Ask if you need clarification.

Could be. I'm far from a pattern guru. The key here is to find an approach that works. If perusing a catalog of patterns give you and idea of how to solve your problem, great, use it. On the other hand, if you already have a solution, and it happens to fit a pattern, then cool, now you have a name for what you did. The wrong thing to do would be to try to force it into a particular pattern that doesn't fit.
The value in patterns is twofold: 1) as a means of communication of some fairly complex, commonly used, abstract concepts, as in, "I suggest a Builder Pattern for this," and the other guy knows exactly what you're talking about, or at least has a general idea and knows where to go for details, and 2) as a catalog of common solutions to existing problems, as in, "Dang it, I have this problem with such-and-such interactions among the pieces, I'm not sure how to structure a solution, but I bet somebody else has done it before... Oh, yeah! Builder Pattern! That'll work!"

Similar Messages

  • Design Pattern for Building Trees (Java)

    I'm wondering if there is a design pattern suited to build trees from a given domain object.
    public interface DomainObject {
    public long getId();
    public abstract class Displayable {
    private DomainObject domainObject;
    private Displayable parent;
    private Vector children;
    public Displayable(DomainObject domainObject, Displayable parent) {
    this.domainObject = domainObject;
    this.parent = parent;
    this.children = new Vector();
    public Displayable(DomainObject domainObject) {
    this(domainObject, null);
    public Displayable getParent() {
    return parent;
    public DomainObject getDomainObject() {
    return domainObject;
    public Displayable[] getChildren() {
    return (Displayable[])children.toArray(new Displayable[children.size()]);
    public void addChild(Displayable d) {
    children.add(d);
    Example:
    DomainObject O
    Displayable D (contains O)
    D's parent is C
    C's parent is B
    B's parent is A
    A does not have a parent
    A --> B --> C --> D(O)
    Method signature
    public Displayable buildDisplayable(DomainObject domainObject);
    So basically pass in a DomainObject (O) and spit out the Displayable (D), with the tree built up to the root (A).

    No I graduated last year from college. I'm trying to improve our SWT/JFace GUI framework. That method signature is just something I thought about. I'm thinking using Factory Pattern will have to do considering I know ahead of time which subclasses of Displayable have parents and children.

  • Design Patterns Support in Jdev 10.1.3?

    Is Design Patterns Support included as part of JDev 10.1.3. I have seen this support in SAP NetWeaver Developer Studio where you have the option of converting existing classes to implement a certain J2EE/J2SE Design Pattern or create a new class(es) to implement a Design Pattern. I believe TogetherSoft has this support.
    Any chances this request is consider in the next major release of JDev 10.1.3?

    Dear Shmeltzer,
    My company just begins the migration from Oracle Form-based application to pure Java EE one. We will be using JDeveloper v10.1.3, persuaded by it fast GUI building, data-binding features. Before that, we have been trying out Eclipse & JBoss.
    We are going to use Swing & JSF for client, and JavaEE 5 for midtier. Persistence layer, will be JPA (EJB3 entity bean persistence) and Spring Framework DAO support. Spring DAO is interesting bcos it gives a consistent style of API (we want to support both JDBC & JPA) and consistent Exception hierarchy too. So our midtier will be partitioned (roughly according to Fowler's patterns) into 3 layers: Service, Domain/Biz Object, Data Access. Thus far is pretty standard.
    We are still pretty new to this ADF, and are still exploring.
    Now, my initial impression with ADF is that it seems to interfere too much with the kind of pattern we had in mind. The fact that ADF hides too much details from us programmers scares me -- it becomes restrictive and we are helpless as to what are going on inside (with those xml, dcx, etc). For e.g. talk about Service Locator pattern, and we cannot seem to figure out how/where it is implemented. Using ADF Data Control and Biz Components will make all the design patterns "disappear" -- we dont see DAO classes anymore bcos it has been automated. It looks more like 2-tier client-server pattern to me. :-)
    We are interested to use ADF data-binding features, so
    1) Is it still advisable to use Spring DAO layer?
    2) Is it possible to just use ADF in the Client / web tier, while the EJB container remains free of ADF technologies?
    Regards.

  • The search for a perfect design pattern

    The search for a perfect design pattern
    I am searching tip to upgrade a labview program used. I am looking for the best approach to make
    my program more robust and scalable.Software and hardware. 
    Today the system consists of :
    GPS, weather station, ultrasound wind sensor, echosounder  and a  webcamera,  all connected to a computer.
    The computer OS is XP pro with Labview version 2009 installed. Except for the webcamera all peripherals have serial communication interface. 
    The webcamera  interface is ethernet.
    Device                           Data type                 Interval                    Interface
    GPS                                NMEA string                1 second                   Serial  rs232
    Ultrasound wind sensor   NMEA string                1 second                   Serial rs232
    Weather, temp,humid     NMEA string               35 seconds                 Serial rs232
    Echosounder                  NMEA string               500ms-5 seconds       Serial rs232
                                                                          (depending of depth)
    Webcamera                    Jpg                           Snapshot on demand  Ethernet
    The tasks to be solved
    All the data have to be stored.
    All the data have to be displayed in real time.
    Weather history data must be buffered to be plotted in a graph (pop-up windows).
    Absolute wind speed and direction have to be calculated.
    Option to send navigation data attached to email at desired time intervals.
    Image snapshot at desired time intervals.
    The data wich streams into the serial ports are not synchronized and vary in intervals . Would it be a good idea to put all the serial peripherals into a serial device server. Is it possible to let the server place a event in my software, to  trigger reading of the data, from the the server.  Or how could that be done in other ways?
    The perfect design pattern
    In version one of the software I use 4 parallel loops to read data at the serial ports, inside these loops the data was separated and outputted to a datasocket server.  I used datasocked read in other loops to present and store data. But it did not look good, and yes it was a mess, a really rat nest. I am looking for a better design pattern.
     Could some kind of producer/ consumer pattern be the way to go?
    Comments and tips are wanted.
    TIK

    Nice Project! Congratulations ;-)
    I am not an expert for large applications. But your project looks nice and manageable. Here my straightforward ideas:
    I would build a GUI, with menu bar, pop-up graph display thing.
    THen low level tasks with each one handling a RS232 device and feeding queues or fireing notifications.
    Maybe handle the snapshots in an event structure on the GUI blockdiagramm.
    When GUI and producer tasks are running, close the gap with a middle layer which captures the data and actualizes GUI by reference. For instance the graph-thing-dialogue triggers a "flush queue" and displays the last 200 entries of the array of data.
    I often run into issues when having defined too many userevent structures. I guess i am too stupid for that. Thats why i rather use queues (when i dont want to loose data) or notifiers (data is up-to-date). Nevertheless I like a "stop-all-tasks" user event...traditionally.
    My team is actually developing a large application. We are using LabVIEW classes and objects.
    So have fun!
    Yours
    RZM

  • Design Patterns w/o EJB

    Greetings, I am attempting to build a JSF application while learning JSR 127 and a few of the J2EE design patterns. The problem that I am having is that I don't plan on using EJB/Spring with my project and many of the tutorials I have been able to find place a focus on the EJB/Spring implementation details which are both overkill for this project. That said, I want to learn the appropriate patterns to build a functional application without catching "pattern fever".
    I have a general idea of some of the patterns I need to use to get from the presentation tier to the data tier, such as Business Delegate and Data Transfer Object. However, I'm not sure I understand how to use these in conjunction with the managed beans facility. Do the managed beans contain (as in composition) the Business Delegate objects? Or do I use a DTO to push the data from the managed bean to the Delegate? How much if any logic do I put in the managed beans if I'm using them in this fashion (or are they basically just fields and getter/setters)?
    All comments or suggestions are sincerely appreciated,
    Jon

    Hi,
    Have you taken a look at Java BluePrints Solutions Catalog:
    https://blueprints.dev.java.net/bpcatalog/
    The Solutions Catalog focuses on different topics specifically so that you can pick and choose which articles are most interesting to you.
    -Larry

  • Producer consumer design pattern

    Hello,
    I am trying to build a simple program that does the following:
    1. when program starts, the indicator is initialized to -999
    2. when Measure button is clicked, the indicator shows random number continuously.
    3. when Save button is clicked, the indicator shows 1
    I use the event-based producer-consumer design pattern and it works great. However, I cannot find a way to allow the CONTINUOUSLY generating of random number when Measure is clicked. Can someone shed a light on it? Thanks a lot for the help. 
    Attachments:
    CommandList.ctl ‏6 KB
    Untitled 1.vi ‏25 KB

    One simple way to do it is to use the Timeout event case. You can modify the timeout value based on what events have occurred. See attached mod.
    Not saying this is the best way. Kind of depends on where the program goes from here. 
    Attachments:
    Untitled 1-2 MOD.vi ‏27 KB

  • [disc]Design pattern - immutable objects.

    I`m working more often with immutable object because it doesn`t cost as much work to keep object consistent. But sometimes an object has to be build or a reference to his child objects has to be set.
    eg
    class A{
        private ArrayList bList = new ArrayList();  
        public A(){}
        public void addB(B b){
            bList.add(b);
    class B{
        private A a;
        public B(A a){
             this.a = a;
    }It`s now more complicated to make a immutable version of A.
    My question is how this problem could be solved. One solution is to add an immutable flag that could be set to true if the last B is added. But this couldn`t be checked compile time.
    Maybe there is a design pattern for this problem.
    I would like to discuss about this problem, so every thought is welcome.

    I have an Immutable Collection wrapper class that I use when I want to have a Collection be read-only.
    If you look at the JavaDoc for AbstractCollection you'll see that the add and remove methods throw UnsuportedOperationException.
    So all you have to do is implement the iterator() and size() methods. i.e.
    public class ImmutableCollection extends AbstractCollection {     
         private Collection collection;
          * only constructor
         public ImmutableCollection(Collection collection) {
              this.collection = collection;
          * returns the size of the collection
         public int size() {
              return collection.size();
          * returns a non-modifiable iterator over the elements of the collection
         public Iterator iterator() {
              return new Iterator() {
                   Iterator iterator = collection.iterator();
                   public boolean hasNext() {
                        return iterator.hasNext();
                   public Object next() {
                        return iterator.next();
                   public void remove() {
                        throw new UnsupportedOperationException();
    }

  • Wpf: Event driven vs MVVM design pattern

    I'm a beginning coder and I've been working on a WPF app for several months now and struggled to implement anything in MVVM due to time constraits to learn so I coded my program the only way to knew how: with code behind, tight coupling, and a whole bunch of
    spaghetti code.
    My program has grown into 20,000+ lines of messy (but working) code that is mostly event driven. The app I am building will probably be used and continue to be developed for years to come, but I will be the only one working on the code.
    However, now that I have time to start learning MVVM, I'm wondering how useful it really is to follow the MVVM pattern. I'm considering refactoring my code into the MVVM pattern but everything seems 100x difficult to do with little documentation. With using
    code behind and tight coupling, I can make the UI do exactly what I want it to do and everything seems like it can be coded so much faster through the event-driven methods.
    How important is it to follow the MVVM design pattern for WPF apps, especially in the long run? Do you think it's a good idea for me to invest my time to redesigning this app and following an MVVM pattern?

    20k lines is a lot.
    That will mean maintenance will be a significant overhead.
    Anything making maintenance harder will mean maintenance takes longer.
    If you're going to do any serious wpf development ( and 20k lines is serious imo) then you should be using mvvm.
    The thing is though, it's different.
    You will need to learn it before it becomes second nature and doesn't appear to be an overhead.
    It isn't true that "everything" can be coded so much faster with event driven methods.
    In fact a number of things are way easier to do using mvvm rather than code behind.
    If that isn't enough to persuade you.
    Teams use MVVM.
    Go to an interview and tell your prospective team lead you think mvvm is no good and you may as well not go to the interview.
    If it becomes obvious in an interview you haven't learnt mvvm then you will not be chosen.
    Teams also use automated testing.
    This is nigh on impossible with code behind and one of the selling points of mvvm.
    You can test without instantiating a view which means you can run thousands of fast tests in seconds.
    That means you can make changes safe in the knowledge you're not breaking stuff you haven't worked on.
    It means someone else in the team doesn't break your code without realising.
    Since UI and code are decoupled you can makes changes to either or both rather easier - that decoupling = flexibility.
    As your code base grows then re-factoring becomes MASSIVELY faster if you have automated tests in place and your layers are loosely coupled.
    I don't know about this paraticular app you have because I don't know almost anything about it.
    If you plan on doing professional wpf development then I suggest you re-adjust your opinions on MVVM. 
    Please don't forget to upvote posts which you like and mark those which answer your question.
    My latest Technet article - Dynamic XAML

  • J2ME framework and design patterns

    Hi everyone.
    I'm thinking of building a few J2ME applications, and was wondering if there are any frameworks for this (i.e. for building midlets)? For web applications you have frameworks like Struts (Jakarta/apache), but I've not found anything for J2ME.
    Also, any known and proven J2ME design patterns would be of great help!
    Thanks for all your help!
    Best regards,
    Arnt

    Hi
    AFAIK there r no frameworks, you dont need them - everything you code should be as simple and straightforward as possible.
    Hmmm... proven design patterns, well, as I've found standard Java DP can't be used in J2ME, cause you need to do everything with small amount of memory and processing power. Object programming is cool, but it makes big impact on speed of code and on size of generated classes.
    And believie me, sometimes those 2-3 kb make difference (eg. on Nokia 6310i, where you have 30 KB of memory, on 3510i it's about 60KB...)
    So, one patter of which I can think about is - make your code simple :)
    regards
    Leszek

  • What kind of design pattern is this?

    Hi ,
    I am just learning the designpattern. So when I went through different kinds of design pattern, I got some doubts as it looks same some design patterns. could anybody please tell what kind of design pattern is the following one?
    public interface IExporter{
         void export();
    public class ExcelExporter implements IExporter{
    public void export(){
    //TODO implementation
    public class CVSExporter implements IExporter{
    public void export(){
    //TODO implementation
    }thanks in advance..

    Well - in structure, it is nearest to the Command pattern as far as I can tellOr Strategy. Or Builder. Several design pattenrs may share the same class structure, the difference is in the context, forces, and the parts one want to be flexible. And if someone wants to make it explicit which pattern is applied, they should name things accordingly.
    As Saish said this example shows little more that inheritance at work. Not a pattern in itself, but a core element of the language. Trying to "identify" a pattern that is not obvious from the context is either:
    - a sign that the original coder completely missed the point of using a pattern (which is, as Saish said too, assentially about communication)
    - a sign that the maintenance coder is looking for patterns where there aren't
    - an exercise question
    but it differs in so much as its motivation is to polymorphically allow the use of different exporters rather than provide a set of action commands.That shouldn't count as a difference, merely as an "application" (it's perfectly valid to have a hierarchy of commands all devoted to exporting, although, as stated, if the original coder applied the Command pattern, he should have made it explicit, by renaming the interface, e.g. to ExportCommand).

  • Design Patterns that are used in standard j2se/j2ee classes/interfaces

    Hi All,
    I am understanding following design patterns (used within standard j2se/j2ee):
    Adapter
    Facade
    Composite
    Bridge
    Singleton
    Observer
    Mediator
    Proxy
    Chain of Responsibility
    Flyweight
    Builder
    Factory Method
    Abstract Factory
    Prototype
    Memento
    Template Method
    State
    Strategy
    Command
    Interpreter
    Decorator
    Iterator
    Visitor
    I want to see if/where these design patterns are used in j2se/j2ee classes/interfaces. i am looking for few examples of standard java classes/interfaces/cases where these design patterns are used by jdk developers.
    for e.g.
    WindowAdapter class is an example of Adapter DP.
    JOptionPane is an exmple of Facade DP.
    MouseListener is an example of Observer DP.
    Similarly, where can find examples of jdk classes/interfaces of the remaining DPs.
    I searched a lot of books, but they explain the DPs by creating their own classes/interfaces.
    I would like to see where these DPs are already utilised in std j2se/j2ee
    thanks,
    Madhu_1980

    877316 wrote:
    I searched a lot of books, but they explain the DPs by creating their own classes/interfaces.
    I would like to see where these DPs are already utilised in std j2se/j2eeWell, you can go through the javadocs first, they sometimes mention the pattern used.
    Then you can get the sources for the jdk and go through the classes yourself, identifying the patterns.

  • Basic design patterns

    I have learnt basic design patterns, such as Singelton, Objects pool, Reflection, Delegation and so on. I would like to build some application, using these patterns for exercise. Can you please give me an idea for such application ? Thanks.

    I have learnt basic design patterns, such as
    Singelton, Objects pool, Reflection, Delegation and
    so on. I would like to build some application, using
    these patterns for exercise. Can you please give me
    an idea for such application ? Thanks.Here are some simple examples that I found helpful. You can ignore the AspectJ parts.
    http://www.cs.ubc.ca/~jan/AODPs/
    regards

  • Design Pattern for ATE

    Looking for suggestions on the best design pattern (using OOP) for an automated test environment application. The current code (LabVIEW only, no Test Stand) has it's own UI and support VIs for selecting the test environment, sequence of tests to run, running a sequence, evaluating test results and outputting pass/fail reports (HTML) and test measurement result files (TDM). The intent was to give the developer a framework where he/she can concentrate on writing the actual tests. Unfortunately, in the environments where it is used, developers always find the framework lacking for their needs and so tend to have their own version by the time they are done. This thing does not scale well nor is it very flexible.
    This framework was originally written with LV 6.1. I put it in a LV2011 Project, but it won't build due to its sheer bulk so it's being run strictly under the development environment (which I hate doing). The whole framework needs a face lift.
    Any suggestions? I've looked at the AF but it seems "over-qualified" for this, plus I don't have a bunch of parallel processes in this case. Things run pretty much sequentially from the get go just by the nature of the testing.
    “A child of five could understand this. Send someone to fetch a child of five.”
    ― Groucho Marx

    You could create pure virtual class that defines your test step API. Methods for the class would consist of things like setup, teardown, execute to name a few. Your developers could use this base class as the template and API for their tests. The methods regulate the format of the data exchange between your engine and their test. I would also recommend that you use packed libraries so that your test steps are basically plugins. Your test sequence would need to contain the name of the appropriate plugin to use in order to invoke the correct test step. This model is flexible and easy to extend.
    We are actually investigating using this same approach for our test system. Our current system uses TestStand and we are going to investigate TestStand 2012 ability to use dynamic dispatch to invoke our test steps. It should be interesting. We use other features of TestStand so it would be nice if we can make this work. In your case a LabVIEW only implementation should be fairly straightforward.
    Mark Yedinak
    "Does anyone know where the love of God goes when the waves turn the minutes to hours?"
    Wreck of the Edmund Fitzgerald - Gordon Lightfoot

  • Designing a smart Swing GUI with design patterns

    Hi !
    I have to build a quite big Swing GUI from
    scratch. I would like to use smart design patterns to :
    * ensure reusability of some components
    * offer a framework-like set of solid classes
    to deal with generic problems
    * try to respect MVC pattern as close as possible
    from the real MVC spirit (not the half MVC
    pattern Swing is build upon)
    Could somebody give me any link towards ressources/docs/articles dealing with how
    to build such a smart Swing GUI ?
    Thanx a lot !

    Hi !
    I have to build a quite big Swing GUI from
    scratch. I would like to use smart design patterns to :
    * ensure reusability of some components
    * offer a framework-like set of solid classes
    to deal with generic problems
    * try to respect MVC pattern as close as possible
    from the real MVC spirit (not the half MVC
    pattern Swing is build upon)
    Could somebody give me any link towards ressources/docs/articles dealing with how
    to build such a smart Swing GUI ?
    Thanx a lot !

  • How can I develop a web application using EJB design pattern?

    I have searched over the web and found quite a lot of tutorials on how to use the EJB design pattern.
    I know that there will be a home interface, EJB object interface and a SessionBean.
    But the tutorials often only cover a single class, this made me unable to get a complete picture of how EJB design pattern can be implemented into a whole system.
    I am now required to devleop an online shopping web application using EJB and JSP page.
    I think I will need to create a lot of classes: Member, ShoppingCart, Product...etc.
    What I want to ask is that, do I need to create a home interface, EJB object interface and a SessionBean for each of these classes?
    I really need some ideas on how to develop this system using EJB + JSP pages.
    Many thanks to you all.

    For every EJB that you want to create, you will need to code a home and remote interface and a bean class.
    You could start getting your ideas here
    http://www.theserverside.com/books/wiley/masteringEJB/
    http://www.coreservlets.com

Maybe you are looking for

  • How do I transfer music from my iPhone to my iPod without a computer ?

    Is it possible to transfer the music from my iTunes on my iPhone to my iPod without a computer?

  • Flash no longer supported by adobe in near future?

    Ls, I am using the trial for flash cs5.5 and air. 2 questions: 1- I just read that flash player will not be supported on the ipads and that adobe is maybe going html 5.5 instead of flash. Does this mean I will not be able to deploy my apps to the app

  • Are inner classes used the same way as derived classes?

    Hi, I got myself a bit confused when I came across inner and derived classes. However, I know that the syntax for both are different. For inner classes: class OuterClass { class NestedClass { For inheritance: class ClassA { class ClassB extends Class

  • Problem viewing ical calendar

    Together with personal calendar in outlook 2013 on pc. I can display them side-by side but want them "one over the other one so called overlay" so all appointments are displayed per day. This used to work for a year until a couple of weeks ago. Iclou

  • Compressing data in Smartform

    Dear All   I am  supposed to  customize   a    Smartforms(HCM)   which   has   a   work   schedule   being displayed  as  follows currently  Week No  1                        Days Off  SAT/SUN            Start Time         End Time               Sat