OO design with Java

Hello I am new to Java and would like to learn more about the OO features of this language.
I am currently working on a personal project and here are the details:
I am currently working with a servlet which in tail will communicate with another class. This class which I will call A acts as a hub between serveral other classes B,C,D,....etc.
So the servlet never interacts with anyother class other than A.
Also the other classes also communicate with each other through class A.
I hope I painted this picture vividly.
Here is my problem or I should say question. Say I have a class C and I want to replace that class with another class C2 which has a similar behavior, how can I design this so that I do not need to change any code in the "hub" class A. In other words I can just plug in a new class into A and remove it with minimal code change.
I already have found a method using inner classes and interfaces but is there a better approach to this or does anyone know of an alternative method.
thank you for any advice/response.
P�man M.

What you have is sometimes called a Mediator pattern with A beeing the mediator. Class A mediates contact with other classes B, C, D etcetera which don't know about each other.
You can make A a Singleton meaning there will only be one A object available in your application.
When any of the classes B, C, D are instantiated they immediately call A to become listeners. Whenever something happens A broadcasts a message to all its listeners which can take some action if they want to. This is called the Observer pattern. The message could consist of a message name and a "state" class with information about the current state of A.

Similar Messages

  • Will Java UFLs satisfy reports designed with COM UFLs

    cr_xi_java_ufl.pdf notes that "When using Crystal Reports" to design reports that contain user-defined function libraries (UFL), you can use only Java UFLs or only COM UFLs, but not both".
    Is that purely a statement about configuring the Developer to access the UFLs or does it indicate some sort of distinction between COM and Java UFLs.
    In particular can I take a report designed on Microsoft Windows and including a call to a UF that happened to be exposed by a COM UFL and then run it under Crystal Reports Server XI R2 for Linux using JRC and have the function call evaluated by a Java UF of the same signature within a Java UFL?

    Business Objects led me wrong.  Java UFLs DO satisfy reports designed with COM UFLs.
    If I take a report that was designed under Microsoft Windows and I added functions that were there via COM UFLs (certainly I have proved it by typing the UFL name in directly into the formula editor; I presume it will also work if you drag the COM UFL into the formula editor) and I then place that rpt file on my Linux machine and view that report using Crystal Reports Server XI R2 and Tomcat and JRC and I have Java UFLs on that Linux machine that have the same name and arguments as the COM one then the report runs OK and the Java UFLs do their job.
    (Now that is great news)

  • Software reuse with Java design patterns

    Anyone have any suggestions on how software can be reused with Java design patterns? Any concrete examples?

    Buy the GoF book. Lot's of examples there.

  • Design metasearch with java

    hi,
    i'm student in computer science and engineering at faculty of electronic engineering
    and i want to design metasearch with java
    can you provide me with some resources about this topic

    please i don't understand
    can you explain more?If you are designing a metasearch with java
    and your first question is: "can you provide me with some resources about this topic?"
    Then it looks like you have tough road ahead of you.
    One thing that will be very helpful:
    www.google.com

  • Should we avoid Graphical mapping and stick with Java mapping?

    After developing mappings in XI for a month, I just don't see any good reasons to use Graphical mappings over Java mappings. Maybe some experienced users here can give me some valid reasons why we should choose Graphical mappings. Here is what I think:
    Disadvantages of Graphical mappings:
    1. No way to perform automated unit testings. This is probably the biggest reason I hate it. You can do some tests manually when you work in Integration Builder. But there is no way you can write some unit testing utilities to automate the task.
    2. Complexity. Even for some simple requirements, your Graphical mappings can become complicated and hard to understand. A lot of times, I find myself staring at several dozens of graphical nodes and try to understand what it does.
    3. Impossible to reuse. This is totally against the DRY (Don't repeat yourself) principle. For example, to generate messages for JDBC adapter, it is common to have two identical fields for primary keys: one in the access node and another in the key node. If you change the mapping logic in one, you have to remember to change the other.
    Advantage with Java mappings:
    1. Fully automated unit testing. You can create JUnit tests along with your Java mapping classes and use Maven or other build tools to perform automated unit testing.
    2. Your choice of XML parsing and binding. With Java mapping, you can choose any open source framework for XML parsing and binding. For example, with XMLBeans, I can convert XML input message to a Java object, transform to another Java object and write to output message. And each Java object is generated from its corresponding XML schema.
    3. Highly reusable. We can use fundamental object-oriented designs to create highly reusable mapping components.
    4. Better version control. Since the mappings are just Java classes, we can use CVS or SVN to track code changes.
    5. Better build tools. We can fully utilize build tools like Ant and Maven to automate the build, unit tests, or even generate documents and mapping web sites.
    So do you guys agree? Maybe I am still new to XI or I am missing some important things. But at this point, I just don't see why I should use Graphical mappings. Is there anyone developing XI interfaces completely with Java mappings?
    Thanks in advance for any comments!
    Kenny Cheang

    Hi Suraj,
    > Since its graphical the blocks will take space, but
    > there is always an adavntage of processing time.
    > Ebven though it may appear bigger, it will take less
    > time as compared with Java code (for the same
    > mapping).
    Could you explain more why the graphical mapping has better performance? I thought the graphical mapping is compiled into a Java class in the runtime anyway.
    > Yes thats there, but same goes with Java mapping too
    > right (if you haven't mentioned it as constants)
    I mainly think about inheritance. If I have to build 10 interfaces and they all have some common behavior, I can create a base interface class to encapsulate the common logic. But with graphical mapping, you have to duplicate them in each interface.
    > Disadvantages of Java mapping:
    > 1. Performance
    Same as above. I just don't see why Java has worse performance. I actually think Java should have better performance. You can optimize the code anyway you want. In some cases, you have to use queue functions in graphical mapping but it's not necessary in Java.
    > 2. All might not be well versed with Java Code(though
    > everyone may know basic java) .
    I am not asking everyone to abandon graphical mapping. I am just wondering which one is better when you have skills for both.
    > 3. Lot of standard functions are available in GM
    > which you can choose, but you have to remember the
    > exact code for those in Java mapping.
    You can create functions in Java too. All you have to do is to remember the function name.
    Kenny

  • BC-XI V3.0 Message Mapping with Java Class

    Hi all
    In the Integretion Builder Design i try to import a Java Class in order to convert a source to a target field. I have created an tested the class with the eclipse V3.0.
    If i import the source in a customized mapping function i always get the error:
    "OFFMANNONLINESHOP_ORDER2SAP_ORDERS05_MSGMAP01 hat keinen Quellkode."    (...message..has no source code)
    I have also imported the import classes in the "Imported Archives".
    This message always appear if the import line for the classes is filled.
    Do somebody knows this problem
    Message was edited by: Christoph Borst
    Message was edited by: Christoph Borst
    Message was edited by: Christoph Borst

    Hi ,
    select XMLTOOLKIT option in Operation mapping and execute it.
    I am not sure we can call java program in XSLT Program,but alternative is copy the code and use it in XSLT mapping it self,that means your XSLT program will become with JAVA extensions.
    then in Operation mapping level select SAPXMLTOOL kit option and execute it. i hope it will work. if it is not working then you have deploy some JAXP files on server,because the way execution of XSLT Mpaping program got changed,like when eve you executing XSLT with extnasions( if you are not using XMLTOOL kit option) then you have to use latest version of JAXP.JDK files.
    Regards,
    Raj

  • A question about design of Java Application on java card.

    Hi every one,
    I have a question about design of Java applet on java card,
    There is an application on my card that it is not java card, it include a DF and some EF under DF, I would like to know if I want to have this application on java card ,how can I design DF and EF on java card ,I mean is there any relation between DF,EF with applet and file? for example can I say DF is same as applet and EF is same as file?
    I'll appreciate for any help .
    yours sincerely,
    orchid

    hi
    you can write a java class for DF.
    an instance of DF class have some EF objects.
    for example,
    samples/com/sun/javacard/samples/JavaPurse/CyclicFile.java
    implements ISO 7816 CyclicFile ( EF )
    see also:
    http://forum.java.sun.com/thread.jspa?threadID=673745&messageID=3936272
    best regards,
    siavash

  • Web site with java benchmarks for various cpus?

    Is there a web site that shows java benchmarks run on various P4 and AMD cpus, so that it is possible to see the relatively speed at which java runs on these cpus?

    You'll find a few if you search around, but none will be meaningful. The problem with Java, or any other Virtual Machine type runtime language is you can not design a benchmark that really has meaning, in any context but the benchmark itself. First off, you're not benchmarking "Java" you're benchmarking the "JVM". I try to convince people to not waste so much time on these speed issues. Your time would be better learning how to write better code, which would give a much bigger speed increase then switching from a P4 to an Athlon. Developers often make mistakes and oversites in their work that slows a program down by an order of magnitude. You're never going to see that kind of performance difference in CPUs. So get a good deal on machine, the most "bang-for-your-buck" if you will, and go to town, and stop worrying, hotspot is fast.
    Sparc Chips are different story because a little thing called register coloring... but you didn't mention sparc chips, so I won't tell the story.
    Spinoza

  • Problems with Java SE6

    Hi. My system is updated (Mac OS X version 10.6.8) but I can not use Java.
    I have enabled "applet plug-in...." in Java preferences - and have seen this
    message on the Java site:
    Java for Mac
    Check your version of Mac OS X. » How do I find my Mac OS X version?
    Mac OS X Version 10.6 and below
    Use Software Update available on the Apple menu to check that you have the most up-to-date version of Java 6 for your Mac. Java 7 is not supported by these older versions of Mac OS X. If you have problems with Java 6, contact Apple Technical Support. Java.com does not provide a download for these systems.
    Mac OS X Version 10.7.3 (Lion) or newer
    Java 7 can run on your Mac. Java 7 requires an Intel-based Mac running Mac OS X 10.7.3 (Lion) or later and administrator privileges for installation.
    » Information about installing and using Java 7 on Mac
    - so must I contact Apple technical support - Java does not supply download for my system?  Am very confused.
    Hope somebody can help
    jeschaz

    Apple barred Java from running on Macs in order to safeguard users by blocking Java 7 Update 11 and adding it to the banned list in XProtect.
    This was the second time in two weeks that Apple had blocked Oracle's code from running on Macs. The threat was so serious that the U.S. Department of Homeland Security had recommended that all Java 7 users disable or uninstall the software until a patch was issued. This time Java is blocked through Apple's XProtect anti-malware feature.
    Java has come under fire as the means by which hackers have been able to gain control of computers. In April 2012 more than 600,000 Macs were reported to have been infected with a Flashback Trojan horse that was being installed on people's computers with the help of Java exploits. Then in August Macs were again at risk due to a flaw in Java, this time around, there was good news for Mac users: Thanks to changes Apple has made, most of us were safe from the threat.
    Unwilling to leave its customers open to potential threats Apple decided it's safer to block Java entirely.
    In order to block older versions of Flash, Apple has updated its "Xprotect.plist" file so that any versions that come before the current one (version 11.6.602.171) cannot be used on a Mac. Users who have older versions of Flash installed will be greeted with an alert that says "Blocked plug-in," and Safari will prompt the user to update to a newer version.
    Macs running OS X Snow Leopard and beyond are affected.
    UPDATE for those running Lion or Mountain Lion:
    Oracle on Friday February 1 released a new version reportedly addressing vulnerabilities seen with the last build.
    Apple disabled Java 7 through the OS X XProtect anti-malware system, requiring users to have at least version "1.7.0_10-b19" installed on their Macs. The release dated February 1 carries the designation "1.7.0_13-b20," meeting Apple's requirements.
    Oracle "strongly recommends" applying the CPU fixes as soon as possible, saying that the latest Critical Patch Update contains 50 new security fixes across all Jave SE products.
    Update for Snow Leopard users:
    Apple issued update 12 for Java for OS 10.6:
    http://support.apple.com/kb/DL1573
    Note:  On systems that have not already installed Java for Mac OS X 10.6 update 9 or later, this update will configure web browsers to not automatically run Java applets. Java applets may be re-enabled by clicking the region labeled "Inactive plug-in" on a web page. If no applets have been run for an extended period of time, the Java web plug-in will deactivate.
    If, after installing Java for OS X 2013-002 and the latest version of Java 7 from Oracle, you want to disable Java 7 and re-enable the Apple-provided Java SE 6 web plug-in and Web Start functionality, follow these steps:
    http://support.apple.com/kb/HT5559?viewlocale=en_US
    Further update:
    Apple issued this Java related security update No. 13 on February 19:
    http://support.apple.com/kb/HT5666
    and Update No. 14 on March 4:  http://support.apple.com/kb/DL1573
    http://support.apple.com/kb/HT5677
    You should also read this:
    https://support.apple.com/kb/HT5672
    The standard recommendation is for users to turn off Java except when they have to use it on known and trusted websites (like their bank). Javascript, which is unrelated despite the name, can be left on.
    Further useful comment in this article:
    http://www.macworld.co.uk/macsoftware/news/?newsid=3435007&olo=email
    However, if you need the Jave 6 JRE and plug-in:
    http://support.apple.com/kb/HT5559

  • What are the limitations of Java,what cannot be done with Java?

    Hello.I want to ask, is there anything which cannot be done with Java related to computer programming ,does Java have limitations?

    BIJ001 wrote:
    You need a JVM to run Java applications.Usually yes but nothing prevents you from writing a compiler to compile Java sources right into native code.@Everyone: Sorry folks, I meant to say "Never say unequivocally that something cannot be done. Time will more than likely prove you wrong."... which I think you all got the gist off, despite what I actually said.
    @BIJ: Hmmm yep, so that sort-of brings writing a device driver in the Java language into the realms of practicality, except you'd still have to work-around the fact that Java is by design a device/OS idependant language, so one suspects that you'd probably end-up using to JNI to call a large and complex library of assembler (or something) functions, which actually do the work... hence you'd probably be better of in assembler, C, or indeed any "native" language, or combination thereof.
    Java excels at writing "large and complex business systems". Java pretty much sucks at writing "low-level CS stuff", which C (and assembler) both excel at... Hence some knowledge of both helps you pick the tool for the task, and create "complementary" layers of abstraction in your application, which (the theory goes) make it robust and flexible.
    I do think that it's interesting that Java excels in exactly the places where C is/was "undercooked".... I do sometimes wonder if that was by design; like the language designers intended them to be complementary tools or something.
    Cheers. Keith.

  • What do you plan to do with java

    I know this is a game development forum, but I had one question. What does everyone 'who is nice at java example abuse' (i'm not saying that no one else is nice, but he's name is the most catchyest) what do you plan to do with java. Do you really want to make games in java for the rest of your life, and prove to the world that java is gaining power? Or you just use java as the jump off point to learn anything else.
    Sorry if i'm getting to personally, but I was just wondering. This is a question to everyone not just abuse. lol

    Development speed:
    C / C++ (DJGPP):
    downloading many parts - 1 week
    installing - 1 weekend
    looking for basic tutorials - 1 week
    getting hello world to work - 1 afternoon
    getting more tutorials - 1 week
    getting past hello world - 3 weeks
    doing something worth doing - never
    total time to becoming a basic C programmer - 18 months & counting (I still try every couple of months, it never works)
    compiling someone else's code - 1% success (only one program not specifically designed for DJGGP ever compiled - C is portable eh?)
    Java
    dowloading JDK - 4 hours
    installing - 1/2 hour
    basic tuts - 1 hour
    hello world - 3 hours (java.lang.NoClassDefFoundException :-) )
    more tutorials - 10 mins
    getting past hello world - 1 week
    doing something worth doing - 2 weeks
    total time to becoming a basic java programmer - 1 month
    compiling someone else's code - 95% success (some people use the GNU regexp and GL4java, now there's regexp & 3D in the main package, so that shouldn't be a problem for much longer)
    Running speed:
    http://members.lycos.co.uk/wjgoh/JavavsC.html
    pure java JITted for the current machine is faster than generalised C, it's just that in C you get like
    prog: printf("xxx\n")
    stdlib: some assembler
    wheras java
    prog: println("xxx");
    lib: print("xxx"+"\n");
    lib: print("xxx\n");
    lib: write("xxx\n");
    lib: write(new byte[] {'x','x','x','\n'});
    lib: native void write({'x','x','x','\n'});
    stdlib: write(bytes);
    stdlib: some assembler
    I know that's not the right chain, I'm just showing the idea. Also you get things like this:
    //deprecated - don't use
    getSize() {
    return size;
    //ok, use this
    getPanelSize() {
    return getSize();
    where it's faster to use dodgy old methods.
    Shish

  • How i can start working with Java?

    Right now i am having only 8 months of exp in ABAP. can any one help me out to start working with Java specially for Netweaver Purpose

    It is great if you can get yourself familiar with java syntax, as is the case with any new langauage. However, the worst thing you can do is just code java in a top down approach. If you are not familiarizing yourself with OO concepts and best practices, then you are going to miss two important benefits that you will get from using OO programming - Reusability and flexibility in the frameworks that you develop (leveraging design patterns).
    These benefits will also be directly obtainable when you use ABAP objects.
    I am working in the opposite direction at the moment. I have some java experience, and I am starting to learn ABAP. I have used ABAP objects in my first project, and it was actually much better than I thought it would to be.
    Java and OO programming will be an ongoing learning experience. You will not be an expert for quite some time. I do not consider myself to be an expert by any means, and I've be studying OO and java for a few years.
    There is a fantastic book that explains OO concepts clearly, in much easier terms than the Gof "Design Patterns" book:
    Java Design: Objects, UML, and Process by Kirk Knoernschild
    You can read a few chapters at www.kirkk.com. (Use the JOUP link).
    Hope this helps you.
    - Brendan

  • Oracle table(s) data to INSERT(String) statements with JAVA

    Hi,
    How can I get sql inserts from a oracle table with JAVA?
    Is there a Oracle API for it?
    I need to store it in a file, the result file should have these examples lines:
    -- INSERTING into TEST
    Insert into "TEST" ("CODE","FAMILY","SUB_FAMILY","SEVERITY","STATUS","ANOMALY_DATE","DESCRIPTION",
    "COMMENTS","VALUE0","VALUE1","VALUE2","VALUE3","VALUE4","VALUE5","VALUE6","VALUE7","VALUE8",
    "VALUE9") values (1,'family1','subFamily11','bad','initial',to_date('0005-11-21','DD/MM/RR'),'someDescription',
    'someComment','someValue','someValue','someValue','uselessValue','uselessValue',null,null,null,null,null);
    the example line was created with the export tool from Oracle SQl developer
    Thks.
    Francisco

    user9046632 wrote:
    Hi Guys, this is me Francisco that wrote the first question, but now I've an NEW account. I'll try to explain it. For a Job I need a .txt file that contains the SQl string inserts from an Oracle Table. I can't use a Software because I need to do it with Java Code. I'm not trying to get the inserts's logging , I need a to export it from a table.I read One way to do it is using DataPump utility, but using this tools, will I get a text file? I read that DataPump works with binaries files. using Java JDBC and metadata, I need to convert all in String file, ok for it I'm agree, but I have to write a lot of code to know what kind of type I get from the Table to parse it. One example is with Date types, oracle softwares parse it as to_date('0005-11-21','DD/MM/RR') and java toTostrig will do it something like '2009-1-25 13:00:00'. Java toString method will truncate some Number types So I need to know if someone did it or give or can help me.
    Thank you very much. Francisco
    Again, explain the business problem you are trying to solve, not the technical one. WHY do you need a text file that contains "SQL string inserts"? It sounds very much like you are looking at your problem "through the wrong end of the telescope" and thus finding a poorly designed solution. But unless we know the real problem to be solved, it's hard to say any more than that this smells bad.
    Sorry about my English, it's not my natural language

  • The performance of management system with Java and MySQL

    Hi all,
    I want to develop one management application with Java and MySQL. However I am not sure which is a good way to design the system. The system has to deal with customers' data in the database.
    Should I create objects for every customers when application starts so that I do not need to access to the database often? Or
    Should I access to the database everytime the user want to deal with customer's data?
    Welcome for any suggestion.
    Thank you
    Pat

    Hi
    i i think u should go through MVC model or use connection pooling

  • Object Oriented Design in Java

    I am an RPGIV programmer trying to switch to Java. I have some experience with Java syntax and basic fundamentals. My question pertains to OOP specifically. I am trying to write a version of the old C-robots program in java. It was an AI simulation project written in C years ago where you could modify the actual AI code and then implement it to test results with 3 other robots with different AI. My question is this: When trying to break down the methods for an interface client to control the robot objects, how do you know what messages that particular client should take care of. In a GUI version I imagine that all the interface client would need to know is basically getPosition() and getDamage() for the display. Then the robot objects would handle all of the other methods including moving(), scanning() and shooting() just to keep it simple. (many more methods are needed, I know). i guess in a nutshell i am trying to determine good program design when it comes to object responsibility. how much responsibility should the interface have as opposed to the other. thank you

    Hi! Welcome to Java. You have a rather broad-based question which primarily deals with good o-o design.
    I'd recommend reading the chapters relating to o-o design from Bruce Eckel's "Thinking In Java". The electronic edition of the book is available for free download at http://www.bruceeckel.com.
    Now, regarding the interface client, you need to determine what other entities it will interact with and from that determine what methods it must have in order to permit those interactions. That's a rather short way of putting it, I know. However, hopefully that's enough to get you going.
    Hope this helps! Feel free to ask if something's not too clear.
    Cheers!

Maybe you are looking for

  • Need advice for an application that restricts access to other applications using a smart card

    Hello everybody, I am developing a system that uses a smart card reader attached to a USB port of a PC. What the system should provide is: When computer boots up and shows the users login screen, a user, previously registered, can use his smart card

  • My iPhone 4S screen is black, only siri works. What's with that? What can I do?

    Hey, I have an iphone 4S. Like a billion years ago the power button stopped working. Havent had problems with it until now, where it suddenly went black while I was using it. Siri still works when I hold down the home button but listening to siri's v

  • Prompt for Filter

    How do I add a prompt (for a date range) to a report to filter out unwanted data?  Thanks for your help.

  • Zend_Amf_Server authentication

    Zend_Amf_Server documentation clearly states that 'if the credentials are received in the AMF request headers'  Zend_Amf_Server can perform authentication. But how do I add credentials to AMF headers ???

  • 1.1.3 software -- why should I update?

    My nano has 1.1.2 software and iTunes reminds me every time I sync that the 1.1.3 update is available. I'm trying to find out what was changed/fixed with 1.1.3 software and can't find anything on the site so far that explains what the differences are