[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();
}

Similar Messages

  • Design Patterns in OO-ABAP

    Hi Everyone ,
    What are design pattern in Object Oriented ABAP.
    How will we know that which pattern suits the particular scenario.
    Thanks
    Sandeep

    Hi,
    yes its not free, but its really worth the money.
    Other abap specific sources:
    http://wiki.sdn.sap.com/wiki/display/ABAP/ABAPObjectsDesignPatterns-ModelViewController%28MVC%29
    http://www.sdn.sap.com/irj/scn/weblogs;jsessionid=%28J2EE3417200%29ID0796789650DB21029243082976783901End?blog=/pub/wlg/606
    /people/marcelo.ramos/blog/2008/04/30/sapmvc-a-new-mvc-for-classical-abap-dynpro
    Greetings,
    DSP

  • ABAP objects design patterns

    hi all,
        can any one send me the Design patterns used for ABAP objects programming in ABAP. eg mvc and sample code which uses the design patterns
    cheers
    senthil

    Of course that program is not an object design pattern
    (Its just a little ABAP Objects syntax demo that I wrote  years ago
    I don't know about a list of OO design patterns implemented in ABAP Objects.
    A very simple one, a Singleton might look like this:
    <b>* cl_singleton: Eager Variant
    CLASS cl_singleton DEFINITION FINAL
                                  CREATE PRIVATE.
      PUBLIC SECTION.
        CLASS-METHODS: class_constructor,
                       get_singleton RETURNING VALUE(singleton)
                                               TYPE REF TO cl_singleton.
      PRIVATE SECTION.
        CLASS-DATA singleton TYPE REF TO cl_singleton.
    ENDCLASS.
    CLASS cl_singleton IMPLEMENTATION.
      METHOD class_constructor.
        CREATE OBJECT singleton.
      ENDMETHOD.
      METHOD get_singleton.
        singleton = cl_singleton=>singleton.
      ENDMETHOD.
    ENDCLASS.
    cl_singleton: Lazy Variant
    CLASS cl_singleton DEFINITION FINAL
                                  CREATE PRIVATE.
      PUBLIC SECTION.
        CLASS-METHODS get_singleton RETURNING VALUE(singleton)
                                              TYPE REF TO cl_singleton.
      PRIVATE SECTION.
        CLASS-DATA singleton TYPE REF TO cl_singleton.
    ENDCLASS.
    CLASS cl_singleton IMPLEMENTATION.
      METHOD get_singleton.
        IF cl_singleton=>singleton IS INITIAL.
          CREATE OBJECT cl_singleton=>singleton.
        ENDIF.
        singleton = cl_singleton=>singleton.
      ENDMETHOD.
    ENDCLASS.</b>

  • Design Pattern and ABAP Objects

    Hello Friends,
    I would like to know, if ABAP Objects can be used to do pattern oriented programming ?
    For example GANG of four has provided almost more then 30 design pattern ( MVC, singelton, Obserable, FACADE,,,etc) can we implement patterns using ABAP ??
    Many thanks
    Haider Syed

    Hi,
    Take a look at the following site:
    http://patternshare.org/
    It has all the basic patterns from the GOF and a lot more. I can recommend the ones from Martin Fowler but be sure you start with the ones from the GOF.
    All patterns are described by using UML so it's very easy to translate them into ABAP OO code.
    Regarding your other question. For the observer pattern I used an interface which the SAP had already created if_cm_observer and created my own abstract observable class. The observable class is nearly a 100% copy of the java.util. one
    regards
    Thomas

  • ABAP Object X Design Patterns X Extreme Program

    Hi Evebody,
    I’m postgraduate in Object Oriented Analysis and Programming.
    I’ve been working with ABAP procedural development for two years and I’ve started to work with ABAP Objects has few months.
    I’d like to get deeply knowledge in my development’s skills, could someone tell me if <b>ABAP Object X Designer Patterns X Extreme Program</b> is a good path to follow?
    I’d like to share material and guides about this topic.
    I’ve already bought these books to help me.
    <b>ABAP Objects</b> - H. Keller; Hardcover <i>(Pre-Order)</i>
    <b>Design Patterns Explained</b> - Alan Shalloway
    I’ll be very grateful with any help.

    > And do you think these themes are a great combination
    > for ABAP development?
    Design pattern are very abstract and can be used with any OO programming language. The implementations will differ but the core concepts are always the same.
    XP is an agile development process and can also be used with any programming language.
    Learning what design pattern are and how to use them is very important in my opinion. Most companies expect that you are familiar and have experience with them.
    Extreme Programming (XP) on the other side is different. When I began to explore XP it got me started on how software should be developed in general. Since the concepts behind XP are quite different, it should at least stimulate you to start thinking about how you develop software at the moment and if there might be better ways of doing it.
    If you have only time to study one subject go for the design pattern. You might also consider reading the following books if you want to improve your OO coding skills:
    <a href="http://www.amazon.com/Refactoring-Improving-Design-Existing-Code/dp/0201485672/ref=pd_bbs_sr_1/102-4989641-7820932?ie=UTF8&s=books&qid=1173448197&sr=8-1">Refactoring: Improving the Design of Existing Code (a true classic)</a>
    <a href="http://www.amazon.com/Refactoring-Patterns-Addison-Wesley-Signature-Kerievsky/dp/0321213351/ref=pd_bbs_sr_2/102-4989641-7820932?ie=UTF8&s=books&qid=1173448197&sr=8-2">Refactoring to Patterns (Shows how to improve code by introducing design pattern)</a>
    cheers
    Thomas

  • Data Transfer Objects Design Pattern

    Hi All,
    Could anyone tell me more about this DTO design pattern, as such when one should prefer it.
    Second is this pattern transaction safe or one would have to implement the same manually. Any updates would prove benefecial to me.

    Hi
    I do not understand what you mean.
    A dto is just an object which you populate in one layer and use in another layer.
    you do not need any jndi look for DTO , instead you lookup for ejbs , datasources ,....
    for example you lookup for some CMP , search and find some CMPs , populate DTO with those CMP and send the DTO to front layer.
    if it is not the answer , can you explain more about your requirements(S)

  • DAO object Design Pattern

    i have to develop a web base applecation which is database indepandent, to achive this functionlity i have to use DAO design pattern.
    can some one explane me more about this............................

    Data Access Object:
    Java BluePrints - Data Access Object
    JavaWorld: Write once, persist anywhere

  • Flex design pattern for BlazeDS transfer objects

    Dear Community,
    I have a question regarding the nature of objects transferd from BlazeDS backend to the Flex client.
    According to some adobe docs all the presentation logic should be in flex and BlazeDS should provide only services.
    The question is what kind of transfer objects should be used? with what level of abstraction?
    To make it more clear let's talk about a simple forum application like adobe forums.
    I have created a Forum service, which returns a Forum transfer object, which has a List of Threads, with each thread having a List of Messages.
    Flex gets the Forum transfer object and does all the presentaiton work.
    This is a very nice seperatin of concerns architecture BUT there are two major performance issues:
    - when the forum becomes bigger the transfer object will be huge
    - the flex will use huge client resources to create the presentation of the forum transfer object.
    So my question is what is your strategy/ design pattern for such a problem.
    An obvious answer would be create services that include the presentation logic and use transfor objects like ThreadListPage which will include only the first 10 threads.
    Thanks in advance

    I think you are going to get a few varied types of answers to a general question like this, but I will comment on a few things.  First, you should only be transmitting the data that you need to use or display to the user at the time.  If this forum was implemented in Flex (I wish) you wouldn't transfer the text for all the threads.  You might not transfer the thread text at all (just the subjects), you'd make calls back to the server to fetch that data when and if you need it.
    Also, I think you are overestimating the resources required for the Flex "presentation layer".  If you think about it, these workstations we have here are pretty idle most of the time when you're at a website.  Nowadays there's plenty of processing power just sitting there waiting, so as long as your design isn't flawed the CPU or memory are rarely going to be a bottleneck with Flex.
    The way I design, BlazeDS (or GraniteDS etc) should mostly just be "serving data".  There is some flexibility available, for example I don't see a problem with putting certain types of business rules (such as a limit on the number of results that can be recieved in a search) within server side code, and validation rules on the Flex side.  So there's not too many "industry standards" in Flex yet beyond maybe what's done in the various standard architectures, at least not that I'm aware of.
    You might find it beneficial to look into some of the various frameworks/architectures available like Cairngorm, Mate, Swiz, and so on.  Learning how they work (looking at examples) would probably answer some of your questions too.

  • Design patterns,about value object ,how?why?could you give me a soluttion

    design patterns,about value object ,how?why?could you give me a soluttion
    use value object in ejb,thanks
    i want not set/get the value in ejb,find the method to solve it ,use value
    object ?
    how? thanks.

    Hai
    Enter your telephone number here, at the top it will say your Exchange, Phone and cabient number. If it doesn't mention cabinet that means you are directly connected to the exchange and not via PCP.
    If you are connected to a cabinet and it doesn't say FTTC is available, ask your neighbor to-do the same test (they have 2 be infinity connected). If they are, then proceed to contact the moderators here. Though it could not be showing because all the ports have been used up in the FTTC Cabinet.
    If this helped you please click the Star beside my name.
    If this answered your question please click "Mark as Accepted Solution" below.

  • 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

  • SERVICE LOCATOR ?? Is it really an interesting Design pattern??

    Hi everybody,
    i've a problem with the J2EE Design Pattern "Services locator" (it's a singleton).
    It is said that by making use of a Service Locator we can :
    - hide to the client the complexities of initial context creation, EJB home object lookup,and EJB objectre-creation.
    - multiple clients can reuse the Service Locator object to reduce code complexity, provide a single point of control, and improve performance by providing a caching facility.
    But i would like to understand at which side should that service locator object reside??!!??
    If it is at server side then the clients need well an initial context in order to make a lookup on that object.
    Conclusion :
    the service locator doesn't hide the complexities of initial context!!
    Furthermore the client has to perform a look-up on that service locator object!! The only advantage left is caching facility.
    If it is at client side, each client needs his own services locator object
    Conclusion :
    multiple client don't reuse the same service locator. What's the advantage to be a singleton ???
    There is certainly something that i don't understand so help me please!! Thanks.

    Hi Yves,
    But i would like to understand at which side should
    that service locator object reside??!!??
    If it is at client side, each client needs his own
    services locator object
    Conclusion :
    multiple client don't reuse the same service locator.
    What's the advantage to be a singleton ???The service locator resides on the client side and is implemented as
    a singleton. Since it is possible that there could be multiple
    class loaders/JVMs on the client side, and therefore, multiple
    instances of the "singleton" service locator. This is typical
    in a distributed environment (e.g. servlets/JSPs in a web-tier
    cluster using service locator). Thus service locator is not
    a truly "distributed singleton" object. But, the empahsis
    is to design the service locator such that it does not hold
    any state that needs to be replicated across multiple
    instances across different JVMs as mentioned. Thus, there
    is no need for multiple clients to use the "same" service locator,
    but still the benefits of implementing this pattern is realized.
    By making it a singleton, and keeping it from holding state
    that needs to be replicated, we realize the benefits of this pattern.
    You may also want to visit the J2EE Pattern interest list
    and see these relevant discussions :
    Topic: Service Locator and passivation
    http://archives.java.sun.com/cgi-bin/wa?A2=ind0106&L=j2eepatterns-interest&F=&S=&P=1026
    Topic: Caching EJBHome interfaces
    http://archives.java.sun.com/cgi-bin/wa?A2=ind0106&L=j2eepatterns-interest&F=&S=&P=9226
    Topic: Using Service Locator for Data Source caching
    http://archives.java.sun.com/cgi-bin/wa?A1=ind0106&L=j2eepatterns-interest#31
    hope this helps,
    thanks,
    -deepak

  • 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

  • Does any body have any design patterns of JSF Web Application Developping?

    Can any one answer me some questions?
    #1.I am an amatuar of people who develop Web Application.For some reason,We choose the JSF to develop our item.through some introduction,I know the UI component of JSF is resided in Server side,is it right?but I am a little confused that:if there are many users who are exploring our jsf website.(to simplify my question,image I had just one web page and just one button)How many UI components(buttons) will be there?How it(they?) works?
    #2.Does any body have the success experience (for example design pattern)to develop web applications?if We just concern about the Add,Delete,Modify,Query operations of some data.
    I just do my job according to my feeling.
    I will give every page a pagebean(backing bean),and I am not sure how to combine the business data with the pagebean.some one suggested that I should use delegate pattern to separate my business log and page logic.But I am still confused by following things:
    #2.1 does JSF have the same ability to help us construct the model dialog just like swing to
    help us control the operation flow?
    #2.2 If there is not,Does the following way work?I put every tabledata's property as corresponed component.if user choosed the row in the table,My Listener will syncronize the row data to the components.But
    #2.2.1 if JSF has the components according to the web users' number,how can My Listener tell which component should be update?Should I maintain the map?
    #2.2.2 If the problem I imaged above is false,Does any body can tell me how to custom      the ListDataModel,so I can use it like Swing?because now I can just use some view data to insert into ListDataModel,but after some selection operation,my business object must be find according to the selected data,it is not an interesting job!
         I am waiting for your advice!

    Ok I'll try to explain Step by step please correct me if I make any mistake because I have not played much with shared variables.
    To create a shared variable to an RT target go to the target if tou have already otherwise add an RT target by right clicking the Project>>Add targets and Devices
    Then in the target Right clikc and select the variable as shown below.
    Then once the Shared variable settings window opens Enter a variable name and then Select the type "Network Published"
    In the right side you can select the data type for the shared variable and even you can choose your custome controls.
    After selecting the data type go for the Network and select buffering if required else leave it if you are planning to use the variable just for display purpose.
    Then you can enable the RT FIFO if required (Not able to explain how it works and why it is used).
    Then after completing the Shared variable setup you can access the variable in the VI in both the Host and the RT.
    You can bind the variable to a control so that if any data from the RT is coming you can read the data from that control.
    Once you have placed your shared variable in the BD you can change the access typr to read or write depending on your need.
    This might not explain the complete shared variable concept but I believe that this would defenelty give you a kick off to start using the shared variable. Please correct or add more comments if anybody know better.
    Good luck.
    The best solution is the one you find it by yourself

  • 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

Maybe you are looking for

  • Read-only/hidden fields in self request form

    I have a prepop plugin for one of the field which generates a number from an oracle sequence, i don't want requesters to modify it, so I would like to either hide it or make it read only. Also, can i put some label/help text to put in some instructio

  • Postcript driver issue with Laserjet Pro MFP435nw

    Product Name : Laserjet Pro MFP435nw OS : Win7 Universal Postscript driver not support in corel Draw for Screen change option for different lpi printout, as hp says it has postscript Emulation 3 support, but it fail with Coreldraw  application.

  • Formatted external hard drive, trying to recover files I missed off when backing up.

    I recently formatted my seagate 500gb external hard drive, thinking all the files/projects were backed up. Some of them weren't (I'm not sure how/why, could be human error or the transfer failed but unfortunately i was rushing and didn't check) but t

  • Dynamic HTML over PeopleSoft?

    Our college Portal site uses a Flash animation to display rotating content relevant to the current semester. My latest project involves presenting users with a static image on the Portal home page if their browser does not have Flash installed. After

  • FM For post outgoing payment

    I can't find the BAPI or Function to post outgoing payments , i need to do the function or bapi not bdc .  Please help...