Bridge Patterns

Hope someone can help. I'm very new to java programming so forgive me if I'm a little vague.
I need to write some code that uses a bridge pattern to write a name (hard coded or passed by args) and a decimal figure (hard coded or passed by args) to either a flat file or a database.
The code should also be able to retrieve these values.
Any tips or code snippets would be appreciated.

The actual code.
Assume I want to write a name and a balance to either
a flat file or a database. I will also want to
retrieve name and balance from either the file or the
database.Ok, I've assumed that - so do I now assume that you're asking how to do these things? And you want actual code? Yeah - about that. The "actual code" likely won't help you, 'cause you won't understand it and then the forum will be flooded with a million more questions about JDBC drivers and/or file IO - and that's no good. Why don't you give it a shot, then post "actual code" here if you run into "actual problems"
Good Luck
Lee

Similar Messages

  • Using bridge patterns

    Hello all,
    I need suggestions from you all regarding the usage of bridge pattern in my problem. My xml file contains an element which when read gives the datatype like varchar , longint. etc..... for each of these i want to give them java types. Like in place for varchar i want to use string. my java class file uses these many times. so i want to create another class where all these mappings will be present. These mappings will be 2 dimentional.... like i should be able to define my datatype also according to defferent databases like db2, oracle etc.
    These mappings will help me reduce redundancy in my java code for reading the types .... coz otherwise there will be too many if else statements to replace each datatype name with my defined string.
    i want to use bridge pattern for this. please someone help me to implement it for my above problem.
    thanks

    Hello all,
    I need suggestions from you all regarding the usage of bridge pattern in my problem. My xml file contains an element which when read gives the datatype like varchar , longint. etc..... for each of these i want to give them java types. Like in place for varchar i want to use string. my java class file uses these many times. so i want to create another class where all these mappings will be present. These mappings will be 2 dimentional.... like i should be able to define my datatype also according to defferent databases like db2, oracle etc.
    These mappings will help me reduce redundancy in my java code for reading the types .... coz otherwise there will be too many if else statements to replace each datatype name with my defined string.
    i want to use bridge pattern for this. please someone help me to implement it for my above problem.
    thanks

  • Can someone help me clarify a bridge pattern?

    So I have this qualm about bridge patterns. A professor I have is telling me I should never be doing switch statements in my driver if I'm using bridge patterns (except for at object creation), but I think he's wrong and I want to clarify when I think you're going to have to use one of two faux pas.
    Let's take a look at the good old Shape example. So we have a Square and a Circle and we want them to be able to draw themselves. The square uses two points (top left, and bottom right let's say) to draw itself and the Circle uses a center point and a radius to draw itself. It's obvious we need a switch statement at creation to determine which one we're making. My question then comes in, what about when we edit it? Let's say we want to change the points in the rectangle or the point/radius on the circle. We'd either need to do one of two things:
    a) if we put our editShape function in our driver class, we'd have to do a switch to see what type of shape we're editing before we can find out if we need to get input for two points or if we need to get input for a point and a radius length, and then pass that to our edit functions within the objects themselves.
    b) the other option requires we have both objects contain an editShape function (which would probably be an abstract method within Shape that we'd override) and each object would implement them different. Within this function, the object itself is displaying prompts and getting input.
    A is clearly not the right choice, because it results in high coupling and we're having to switch on our objects and we'd have to change the code every time we add new shape classes. B makes sense because we can just call Shape.editShape() from the driver and depending on which type it is it will ask for the proper input from within the object. However, I thought it was bad practice to have input (specifically prompts and scan reads) from within an object.
    Is this where the bridge class comes into play? For example, would I have a ShapeIO class (which could then have an extended ShapeIOConsole class possibly vs a ShapeIOFile class that would read input from a file?) that would contain the prompting from there? And then that class would handle all possible inputs I'd be prompting for?
    E.G. ShapeIOConsole.getPoint() would have the scanner and prompting calls and would return a Point while my Shape.editShape for Square would just call ShapeIO.getPoint() (assuming I have a ShapeIO object within Shape that's been instantiated as a ShapeIOConsole object) to get two points and my Shape.editShape for Circle would call a ShapeIO.getPoint() and a ShapeIO.getRadius? This would mean anytime I have a new Object that has a new type of property to get input for, I'd have to add a function to my ShapeIO, right?
    Anyways, I hope that made some sort of sense. I guess my question is am I correct in most of what I said, if I even said it clear enough for anyone to understand it ^^.

    benirose wrote:
    Thanks for your reply lance! I have a few responses if it's not too much trouble:None at all.
    >
    >
    >>
    That isn't obvious to me at all. Why do you need a switch?
    I would assume you need a switch statement because you need to know what constructor to call, right? For example if you have Shape myShape, wouldn't you need to determine if you're instantiating that as a Square or Circle? I mean you could do it with if statements and not a switch, but you'd need to conditionalize (is that a word?!) the creation, correct?Presumably something has caused the need to instantiate a particular shape. Let's suppose that the action that caused it was that a user pressed a button on a GUI. Now presumably there is a button for a new circle and another button for a new square. Each of these buttons can have their own event handler. The event handler for the 'New Circle' button can instantiate a new circle (or call something else that does it) and the event handler for 'New Square' can instantiate a new square (or call something else that does it). Where does the conditional logic come in?
    It could be that your user interface is a text based list of items to create, and the user has to type a number to choose. In this case, you might need to do some conditional logic, yes.
    Of course there are times when context is not given or insufficient. Often at the fringes of systems, when interacting with other systems, you need to determine what kind of message you've been given before processing it. But even then, there are usually better ways than lots of conditional logic (dispatch tables, for example).
    Having said all of that, I have worked on a system where a GUI had something like 150 different buttons / menu items / other things that could cause actions to occur. The original developer had decided to give each of these things a number so that he could save himself the bother of creating a new ActionListener or whatever for each item, and routed every action through the same switch statement to try to recover the information he'd just thrown away. Bizarre.
    >
    >>
    You could use a visitor rather than doing a switch.
    I don't really know much about the visitor class, but I'll give it a look.
    I assume you mean 'from within a "domain model" class'. I think the bad practice you're referring to is the failure to separate model concerns from view concerns (or, more generally, the failure to separate the concerns of different domains).
    Yeah, I suppose so. I just don't see many classes asking for it's own input, you usually pass it from the driver class. There's no editString() function which asks for input of a new string, you do that in the driver and then set the new string.Try not to think in terms of a 'driver'. This suggests procedural thinking. Think instead of a collaborating eco-system of objects where one object may delegate to another to do some work on it's behalf. The delegator may, when delegating, also give the delegate something that it might find useful to do its work (such as a means of obtaining data or something that it can further delegate some of the work to). If you do it right, the delegate only sees an abstraction appropriate to its place in the eco-system, behind which could exist any number of implementations. If you're just starting out, this may seem a bit heady. Don't worry about it, it'll come...
    >
    >
    >>
    I wouldn't necessarily do any of it this way; I'm only trying to address your question about Bridge. It probably is a good idea to go and talk to your professor again. If you do, come back here and tell us what he said...
    Yeah, I'm not sure I'd do it this way either, but the assignment is a Survey taking program, and the basic implementation was to have an abstract Question class which has a two level inheritence tree of MultipleChoice, Essay, and Matching inheriting from Question, and TF, Short Answer, and Ranking inheriting from MC, Essay, and Matching respectively. So our Survey class would have a Vector of Questions, which is fine, but he said we couldn't do any conditioning to see what type of Question we have, and that we should just be able to make calls to abstract functions in Question that will handle everything.It sounds like he's trying to get you to put behaviour into the Question subclasses, rather than having it in the Survey (i.e. to do what I said above :-). This may feel a bit strange at first, and you might be saying to yourself 'I thought OO was supposed to model the real world, but a question doesn't do anything in the real world'. One of the core concepts in OO is that if you find yourself doing something to an object in the real world, then ask the object to do it for you in your model. That way, system intelligence gets distributed evenly throughout your model.
    You do run into odd issues though. For example, in a library, suppose you have a book and a bookshelf. Supposing the book has just been returned to the library, should the book now goBackToShelf(), or should the shelf receiveBook(). It might even be both under some circumstances. It could also be neither, if you decide that a Librarian is part of your model. But be careful about doing that. You could get all of your behaviour concentrated in the Librarian with everything else in the system being dumb containers of data (some might argue that would be a good thing).
    >
    On a side note, I know if you type a variable with the abstract class (E.G. Question) and then instantiate it as an inherited class (E.G. MC), you can only make calls to the abstract functions (at least Eclipse tells me so). Is it the same way with an interface? What if my Question class wasn't abstract, then I should be fine, right?You can only make calls to the methods declared by Question and it's supertypes (it doesn't matter whether those methods are abstract or not). This is the same for interfaces and it would also be the same if Question was not abstract. The reason is that when you have a declaration like this
    Question question;you are defining a variable called 'question' of type Question. The only things you can ask 'question' to do are those things that its type knows about, which are the methods declared by Question and it's supertypes. The fact that 'question' refers to an object of some subclass of Question doesn't matter. All that matters is the type of the variable, which is Question.
    Regards,
    Lance

  • Question about bridge pattern

    its definition is "decouple an abstraction from its implementation so that the two can vary independently". I don't understand what "abstraction and the implementation vary independently" really mean and how .
    Before another question pls see the below class diagram of bridge pattern:
    http://images.cnblogs.com/cnblogs_com/zhenyulu/Pic91.gif
    My question is whether not using abstraction and just keeping implementation hierarchy can do the same thing? Interface and its implementation itself(polymorphism) can make extending easily and be well subject to open-closed principle,can't they?
    Sorry for my bad English.
    Edited by: fxbird on 2011-7-17 上午5:13

    fxbird wrote:
    jschell wrote:
    fxbird wrote:
    I think it's very common in j2ee development. Certainly isn't if someone is using a container.
    If someone is creating a container then I would suspect that such a pattern might be useful.
    However if someone is creating a container then there are going to be a lot of useful patterns. And lot of classes as well.
    And in total of the entire scope of creating a container the bridge would be a very small part.
    So it certainly isn't going to be "common".Hello jschell , what do you mean by 'container'? You phrased your comment about J2EE. A common idiom is to refer to a J2EE (actually newer name is JEE) server as a JEE container. Not sure why specifically that word is used but maybe because such servers are said to 'contain' applications.
    In my previous reply, the architecture I mentioned is ss(spring+struts2.x),the pattern I mentioned is a standard way. You either do not understand what I said or you do not understand what happens in those implementations.
    If I have 100,000 classes and 3 of them are implementing the bridge pattern then it is not "common".
    If I have 100,000 classes and 3,000 of them implement many bridge patterns (and not generated) then one could say it is "common".
    And having done some JEE applications I seriously doubt there is an implicit need to use the bridge pattern.
    The bridge pattern is intended to deal with a complex situation. Since there are more simple JEE applications than complex ones then it seems unlikely that there is a "common" need for it in JEE applications.
    Actual I've not been understood why it's used this way---define business interface, from my perspective, it doesn't have to define it, simply writing a business class and calling dao method is enough. I assume bo interface thing is a bridge pattern.I don't know why they would use the bridge pattern nor even if they really do. I wouldn't be surprised that it is used and I can also suppose that the use would be a good idea. Although it is quite possible as well that it is used incorrectly in some places.

  • Do I use the Brdige pattern for this problem ?

    Hello
    I'm making a music mixer for mobile phones. For the canvas, i divided it up in tiles, to fill
    up with .png images if you want to place a sample in that specific tile. But if you have a phone with no colors and your screen is not big enough, the image is almost all black. So I want to create a different class, to only show a letter or a simple symbol if you can't handle the .png well.
    I read about the bridge pattern, where you encapsulate the implementation in an abstract class and seperate it from the base class with the abstractions. Should I use this pattern for my problem ? I have some doubt because I have multiple implementations (color vs non-color) but I don't have multiple abstractions (a tile to fill up with a symbol or picture).
    Are there other patterns that are more suited for my problem ?
    What about the implementation? Should I see the implementation as only producing the image or symbol, or should i see it as the whole canvas, with the tile system?
    For example, now the tiling looks good on most of the targeted phones. But what if the next generation of mobile phones has a screen with very different dimensions. Wouldn't it be better to incorporate this also in the implementation ?
    Thanks

    What are you trying to do when you say "When I put the password for my apple ID into icloud- it keeps reverting to another password"?
    Where are you doing when you try to enter your password?

  • Design patterns implemented in java API

    Hi,
    I have some questions on design patterns implemented in core java class or in general in java API.
    1)Whether
    java.util.Collections, the checkedXXX(), synchronizedXXX() and unmodifiableXXX() methods.
    can be considered as a decorator pattern?
    2) Whether
    LinkedHashMap(LinkedHashSet<K>, List<V>) which returns an unmodifiable linked map which doesn't clone the items, but uses them
    can be considered as a Bridge pattern?
    3) Whether Facade pattern is implemented in java ? If so which API uses it?
    4) Whether
    •     All non-abstract methods of java.io.InputStream, java.io.OutputStream, java.io.Reader and java.io.Writer.
    •     All non-abstract methods of java.util.AbstractList, java.util.AbstractSet and java.util.AbstractMap
    can be considered as a Template method pattern?
    5) Whether
    •     java.util.Comparator#compare(), executed by among others Collections#sort()
    can be considered as a Stratergy pattern?
    6)
    Whether State pattern is implemented in java ? If so which API uses it?
    7)
    All implementations of java.lang.Runnable are considered as a Command pattern.
    8)
    Whether
    •     java.io.InputStreamReader(InputStream) (returns a Reader)
    •     java.io.OutputStreamWriter(OutputStream) (returns a Writer)
    can be considered as an Adapter pattern?
    Please clarify.
    Thanks.

    What do you think, and why?

  • Advice for using patterns

    Hello all,
    I need suggestions from you all regarding the usage of bridge pattern in my problem. My xml file contains an element which when read gives the datatype like varchar , longint. etc..... for each of these i want to give them java types. Like in place for varchar i want to use string. my java class file uses these many times. so i want to create another class where all these mappings will be present. These mappings will be 2 dimentional.... like i should be able to define my datatype also according to defferent databases like db2, oracle etc.
    These mappings will help me reduce redundancy in my java code for reading the types .... coz otherwise there will be too many if else statements to replace each datatype name with my defined string.
    i want to use bridge pattern for this. please someone help me to implement it for my above problem.
    thanks

    i want to use bridge pattern for this. please someone
    help me to implement it for my above problem.What kind of help do you need? It strikes me a little unusual that you would think you want or need the bridge pattern without knowing how to implement it. Generally, you'd learn a pattern first, then recognize a place whereby you could apply its principles, not the other way around...

  • Which pattern for this scenario ?

    Hi all,
    I have an EJB which connects to an external system (written in Perl) using plain HttpConnections and posting HTML content.
    I would like to centralize this access using a design pattern.
    Which pattern is would fit this scenario ?
    I wonder if I should use the Adapter pattern or the Bridge Pattern.
    What do you say to it ?
    Thanks
    Francesco

    I'd kind-of guessed it was uni work :-)
    in all honesty, I wouldn't even approach the problem from a patterns perspective. all I see is a subsystem I don't want to deal with directly, so I define an interface to hide it behind. could argue that it's an Adapter, since it's taking the Http interface and abstracting away from it, to a java one. on the other hand, since mucking around with Http in java isn't exactly straight-forward, you're defining a more simple interface, so it could be considered a facade. which do you think is closer?
    most people, once au fait with design patterns, think less in terms of those patterns, and more in terms of what OO principles to apply. score some extra credit by writing a passage about how design patterns are not prescriptive, and that many coders lift ideas about encapsulation and separation from patterns, rather than use the pattern exactly as described.

  • Synch proxy with synch JDBC using BPM

    Hi All,
    I have a synch proxy to synch jdbc interface. Actually I need to make two JDBC calls by one synch proxy and collect their data in PI and send all data back once to proxy.
    Since I need to make two calls and collect data in one table and send it back to proxy I will have to use bpm in it.
    Can anyone please suggest the architure and suitable blog for the same.
    Thanks and Regards,
    Atul

    Check for sync - async bridge scenarios in the forum. You would need a BPM stadard sync-async bridge pattern.
    VJ

  • Some Questions on BPM

    Hi Master,
    I Attended the one Interview...I have some Questions, Please Reply ASAP..
    <b>What is Pattern</b>? Why we are using with Real time Example.
    Thanks & Regards,
    SReddy

    Hi,
    As moorthy already said pattersns are like templates that can solve many of the real time scenarios either as given or with some customization.
    In BPM there are different patterns and each one having some sub patterns within them with slight variations.
    Some Patterns are,
    1. Multicast Pattern.
    2. Serialization Pattern.
    3. Sync/Async Bridge Pattern.
    4. Collect/Bundle Pattern.
    You can go thro this help link for more examples in Patterns,
    http://help.sap.com/saphelp_nw04/helpdata/en/de/766840bf0cbf49e10000000a1550b0/content.htm
    Regards,
    P.Venkat

  • Clarification of the handle/body idiom in multi threaded applications

    Hello
    As some DBXML classes use the handle-body idiom (handle/body idiom in some docs), could someone please clarify the consequences of that in a multi threaded application like a web container?
    For 100% Java people, like me, this is known in the Java world as 'programming towards interfaces', or as the Bridge pattern; which is seen as good practice.
    Let's take an example. The class XmlQueryContext is not thread safe, but it has a copy constructor. Imagine that your web application has one XmlQueryContext, that we never use in a query, but that we prepare only to be copied in new threads. Is it thus safe to instantiate various new XmlQueryContexts using that copy constructor in various new threads and use them simultaneously?
    Thank you
    Koen
    PS What I am really asking here is if somebody could please translate the following to Java parlé:
    A copy constructor is provided for this class. The class is implemented using a handle-body idiom. When a handle is copied both handles maintain a reference to the same body.

    As a Java user you do not have to worry about how the C++ copy constructors behave. In the Java API if a copy constructor exists for the object, then the copy constructor will copy all of the original object's data into a new object (XmlContainer is the one exception to this rule, generally one should not use that copy constructor at all). So in short, what you plan to do will work.
    Lauren Foutz

  • Reg:BPM Scenario

    Hi All,
    My scenario is Portal(SOAP)- - - R/3(RFC)- - -  MDM
    The webservice(Asyn) is being triggered from the portal ,it will update the data into ECC system by using a RFC(syn)  and from the response(status) of the RFC the message is passed to the MDM server.
    Could anyone suggest me on how to proceed the above stated scenario.
    Thanks in Advance.
    Regards,
    Lavanya

    Use Async  Sync bridge pattern with BPM
    Soap sender (async) ---> RFC(sync) --> Proxy or Idoc (async)
    For Soap sender refer this document
    To configure Asynchronous
    use Quality of Service:  Exactly Once 
    Follow this link for soap sender configuration
    http://help.sap.com/saphelp_nw04/helpdata/en/fc/5ad93f130f9215e10000000a155106/content.htm
    For Async sync pattern use this link... also Refer below link does RFC (sync)
    http://www.riyaz.net/blog/a-step-by-step-guide-to-bpm-asynch-sync-bridge/technology/sap/170/
    For Proxy or Idoc at the target side... This below link gives abap proxy receiver details
    http://wiki.sdn.sap.com/wiki/display/XI/Step-by-stepFTPtoABAPProxy
    Hope this helps.

  • HT5544 Purchased books won't let me read my book

    I paid for a book a few months ago and decided to read it again. I went to my purchased books, but it's not available to re-download. It is trying to make me purchase the book all over again. I was never refunded my purchase and I didn't delete it. Please help!!!

    There may be a background photo missing. Check in the layout options, if one of your pages is using a photo background - the gray "Golden Gate Bridge pattern".
    Then you need to drag a photo to the empty background of the page are select a different background pattern.
    -- Léonie
    Added: The screenshot is from iPhoto 9.5 on my mac - what is your iPhoto version?

  • Looping in Mianstage? Stock Looback? Mobius? Other?

    So I REALLY want to loop in Mainstage. I am still new to the loopback feature, but I'm already feeling that it is a lesser looper than my hardware version (boomerang.) I am hearing things about the Mobius looper. Is that an option in Mainstage? Are there other options? I usually use my looper to in three ways: serial sync (where I lay down a short rhym and then sync other loops up to it) or in a standard verse, chorus, bridge pattern. Oh, and I like to be able to layer over the top of any of those things I laid down.
    Any suggestions? I'm willing to invest the time necessary to learn this, but I'd like to start with the best option before I learn it up.
    Thanks!

    I think that LoopBack (included) is a pretty good plugin. The only difficulty is that you need to map separate controls to each looper - this works if your foot controller can have it's own banks setup, so you would switch banks on your controller to control different LoopBack instances. Works well and everything can sync up with other things in mainstage (Ultrabeat patterns/PlayBack tracks).
    SooperLooper (Another free looper) has some better control options, but getting it to integrate with mainstage can be a bit more difficult and buggy, at least the last time I tried. http://sonosaurus.com/sooperlooper/ . The developer was very friendly when I made suggestions - implemented them the next week. Can't beat that. I can't remember the details of how I got it all working with MainStage - it's been a while, probably set it up on a bus at the concert level. However, I do have a video up showing it in action here: http://www.youtube.com/watch?v=Y7V-E5tT5zc
    I need to check out mobius. If it runs inside a AU plugin and syncs up and simplifies mapping, that would be great.
    Message was edited by: sam squarewave

  • How to preview a .PAT file in Bridge (Photoshop Pattern File)

    How can I preview a pattern (.PAT) file in Bridge?  Bridge seems to be able to preview just about anything, but .pat files just show up with a default PS icon.

    I don't see that as one of the supported files in Bridge (preferences/file type associations), so would guess you have to live with default icon.

Maybe you are looking for

  • Report for Material at subcontract AND PO number

    We are preparing for Inventory verification at subcontractors. My boss believes it would be easier for the SC vendor if we could supply the PO number for which the material was shipped. I haven't found such a report.  Is there one? If you know the ta

  • Mid month payroll area change

    Hi, i am at the client site and I have been asked to change the payroll area of few employees in the system but system is not allowing me to do that. What is the best possible solution so that i can change the payroll area so that the changes are ref

  • Print Button on JSP page prints title,time etc

    Hi I have aprint Button on my jsp page which prints whatever I want selectively using the <style tags> <style type="text/css" media=print> .noprint { display: none} .noscreen { color: black } </style> <style type="text/css" media=screen> .noscreen {

  • ADOBE Interactive Form in webdynpro not allowing to enter value

    Hi,      I have developed a Adobe interactive  form in SFP and then i developed webdynpro component , then integrated into webdynpro. while running the webdynpro application which is showing the adobeform but the input fields are not allowed to enter

  • Xclock - solaris 8

    Not sure this is really the right forum for this, but I couldn't see where else to post it. My customer wants to use xclock to have a permanently displayed clock on the screen for the user. The system is a network monitoring one, so they need to be a