Get instance method and design pattern

Hi All,
1. I New to abap objects and i read the help and some stuff from the forum,
l like to now more about design pattern in abap objects,
2. I saw in some abap class the use of method of GET_INSTANCE i think it's from factory pattern , what is the pros. and cons to use this method ,when i should consider to use it ?
Thanks in Advance
Nina

Hello Nina
A very good introduction into design patterns is the book "Head First: Design Patterns". Here you will find many good reasons why and when to use the factory pattern.
You should use the factory pattern when
- you want to prevent "direct" instantiation (i.e. using a public CONSTRUCTOR method) by the developer
- you want to hide the complexity of instantiation from the user of the class
- the instantiation creates an implementation of an interface and you want to keep control of which implementing class is returned
Regards
  Uwe

Similar Messages

  • Singleton Class using a constructor not a get Instance method ?

    Hi,
    I have a class with a couple of contructors, the class is instantiated many times in the application.
    Is there any way by which I can return a single instance of the class when the contructor is called ?.
    I dont want to declare a get instance method to return a single instance is it somehow possible to do this in the contructor itself.
    This is done so I dont have to refactor the whole application and change all the places where this class is instantiated.
    Example
    XXXClass xxx = new XXXClass();
    every time new XXXClass() is called the single instance of the class must be returned.
    I dont want to implement
    XXXClass xxx = XXXClass.getInstance();
    Thanks in advance
    Rgds
    Pradeep Thomas

    Pradeep ,
    You see a constructor does not return anything
    when you tell java
    String str = new String();
    It is into the reference str that a Object of the type String is assigned and used ..
    If you want a single instance to exist in your application ..the best way is to use the singelton approach.
    Alternatively you could create one static instance of the object in a parent class and all the classes that inherit from it will then share access .

  • Finding instance from variable design pattern required

    Hello guys,
         In my appication I need to get instance of a class from its instance variable.
    Let me explain in deep.
    I have one class ServerConnection in which I accept connection from client as a SocketChannel..
    In the same class I pass this channel variable to new Player construcotr and create one Player class instance.
    Now each player has it's own channel.
    My problem is that when particular channel closed I have to identify particular Player from so many player..
    So how can I identify that instance..
    I can do this by comparing socket port but there are so many players instance so it is some burden some.
    I need some pattern which can help out me to identify particular player by simply passing Socketchannel as parameter..
    Please help me out.

    Hello Nina
    A very good introduction into design patterns is the book "Head First: Design Patterns". Here you will find many good reasons why and when to use the factory pattern.
    You should use the factory pattern when
    - you want to prevent "direct" instantiation (i.e. using a public CONSTRUCTOR method) by the developer
    - you want to hide the complexity of instantiation from the user of the class
    - the instantiation creates an implementation of an interface and you want to keep control of which implementing class is returned
    Regards
      Uwe

  • How to call Instance Methods and set property values in BAPI?

    In Project systems, for the three business objects viz.
    Network, ProjectDefinition and WBS, there are two kinds of methods which are available : class methods and instance methods. We have tried calling some instance methods, for instance, BAPI_PROJECTDEF_GETDETAIL to get details pertaining to a project. While importing this BAPI, it shows two elements for mapping i.e. Current Internal Project(string) and Current External Project(string). We supplied these values for an existing project. Upon running this call through an XML client at our end, it
    returned an error "Module Unknown Exception". This general message is present on every instance method thus far. Upon searching in BAPI Explorer for Project System->ProjectDefinition->GetDetail, we found that this BAPI didn't take any input parameter.
    Following message was displayed in BAPI Exlorer for this BAPI:
    "... Obligatory import parameters are the external and internal keys CURRENTEXTERNALPROJE and CURRENTINTERNALPROJE of the project definition.The system reads parameters contained in the structure
    BAPI_PROJECT_DEFINITION_EX ..."
    i) How to supply the values of Obligatory import parameters.
    ii) What are the possible causes of this exception.
    iii) How to call an instance method. We are using same mechanism for calling class as well as instance methods so far, we have been to call only class level methods successfully. Is there anything special that we
    need to do to call instance methods.

    Hi,
    what version is the SAP PS running?  If WebAs or higher,  create an inbound synch interface containing your two parameters in the request structure and as many as you require in your response structure.  Generate an Inbound ABAP proxy, where you can plug in some code, i.e. create and instantiate an object of the required type and make the call to the BAPI.
    If SAP PS on lower than WebAs, then create a wrapper function module and make it RFC enabled.  Then plug your code in here and do the same thing.
    Watch out for commits!
    Cheers,
    Mark

  • Best architecture and design pattern to use

    I am currently designing a moderately sized LabView application and cannot decide on the best architecture/design pattern or combinations thereof to implement.
    The program basically polls an instrument connected to a serial port continuously at a 2-10Hz rate. When operator clicks a button to start a run, the polled data is then filtered, has math functions performed on the data, writes collected data to files, and produces reltime graphs and calculates point-by-point statistics. At the completion of a run, some additional data files are written. I pretty much know how to accomplish all these tasks.
    What is also required is main-vi front panel interaction by the operator to access a database (via a C# dll with .Net) to query for specifications to apply in order to determine pass/fail status. Setup conditions also need to be changed from time to time by the operator and applied to the data in real time (ie- a measurement offset). I have prototyped the database portion successfully thus far.
    For the main vi, I started off using the Top Level Application Using Events design pattern (Event structure within a while loop). Copious use of bundled clusters and shift registers keep the database data updated. I cannot figure out how to have the top level vi concurrently poll the serial device as outlined above. The Event structure is only active when defined control values change, and use of a timeout is no help since it prevent data from being collected while the user is accessing the database. All database and setup parameters must be applied to the data as it comes in from the serial port. Error trapping/recovery is a must.
    I believe what I need is two parallel processes running under my main vi (one for database and setup, the other for polling and data processing/display, but what would be the preferred choice here?
    Revert back to a polled loop in lieu of Events, use notifiers, occurrences, user-defined events, Producer-consumer loops?
    It�s been about 3 years since I have had an application on this level (which used a state machine architecture), and a lot has changed in LabView (using 7.1 Prof Devel). I am currently having a mental block while trying to digest a lot of features I have never used before.
    Suggestions Welcome!
    Thanks.
    ~~~~~~~~~~~~~~~~~~~~~~~~~~
    "It’s the questions that drive us.”
    ~~~~~~~~~~~~~~~~~~~~~~~~~~

    I suggest a (3) state machine(s) architecture. The first is the user interface. Your main VI is a good start. Another state machine handles the instrument I/O (your serial polling). The third handles all data processing. The three loops run independently. Each has a wait to allow LV's scheduler to share CPU time among the loops. I like queues or functional globals for inter-loop communications.
    This allows a lot of flexibility. Each portion can be tested alone. Each can have different timing and priority.
    Spend some time thinking about what needs to be done and plan the structure carefully before you do any coding (except for little test programs to try new ideas).
    I also like Conway and Watts "A Software Engineering Approach to LabVIEW", published
    by Prentice Hall.
    Lynn

  • EJB and Design Patterns

    Hi all,
    Which design patterns could be applied in coding EJB? I don't know if my question is clear enough, but what I really want to know is which design patterns I could use with EJB and how could I use them this way? (Some example situation)
    Regards,
    Filipe Fedalto

    i think it depends of what u intend to do..
    e.g. i think (maybe i'm wrong, any relevant replies are welcome!) that u could use a stateless session bean to implement some facade, delegating entities creation to some non-bean classes? or why not a stateful session bean to implement a factory (when entities creation depend on client preferences)?

  • 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

  • Difference between n-layer software architecture and MVVM design pattern?

    hello everyone,
    I am not clear with this concepts of Software architecture pattern and design pattern.
    I am developing an wpf application using MVVM. Now, my question is, does MVVM come under n-layered architecture? 
    or n-layer architecture and MVVM both are different? 
    Regards,
    Rakesh.N
    Rakesh murthy

    "
    Now my question is, i want to process the data which i get from database. where should i write that processing logic after getting the data from database? in model classes? or in view model classes?
    The model is however the data comes from wherever it comes from.
    If there is any processing after you get it then that would be in the viewmodel.
    The viewmodel adapts your data to the view.
    If it needs any adapting then the viewmodel does that, not the model.
    EG here
    protected async override void GetData()
    ThrobberVisible = Visibility.Visible;
    ObservableCollection<CustomerVM> _customers = new ObservableCollection<CustomerVM>();
    var customers = await (from c in db.Customers
    orderby c.CustomerName
    select c).ToListAsync();
    foreach (Customer cust in customers)
    _customers.Add(new CustomerVM { IsNew = false, TheEntity = cust });
    Customers = _customers;
    RaisePropertyChanged("Customers");
    ThrobberVisible = Visibility.Collapsed;
    That logic is in a viewmodel.
    in this context , in which layer the viewmodel and model classes are put under in n-tier architecture?
    They're in two of the n layers/tiers.
    Or they're in one.
    Depending on how someone decides to classify a layer or a tier.
    There is no absolute definition.
    Why would you care?
    Hope that helps.
    Technet articles: Uneventful MVVM;
    All my Technet Articles

  • Name of the design pattern

    Hi
    I have been studying a piece of code somebody else wrote. I am wondering if this is the Factory Method design pattern that this represents. I am new to patterns and I would be very thankful for any suggestions.
    public class Creator {
         public Person create(String gender) {
              if (gender.equals(�M�)
                   return new Male();
              else if (gender.equals(�F�)
                   return new Female();
              else
                   return null;
    thanks in advance

    Yes, you are right this is a Factory Method creational design pattern.
    See http://en.wikipedia.org/wiki/Factory_method_pattern for more information.
    Ussualy class which is used to create instances of other classe called XXXFactory and implemented as singleton.
    Regards,
    Yevhen

  • Life cycle and desing patterns

    Hi Friends,
    I am new to SAP BI/BW and learned extract and Reports
    Now i am getting some doubts like what sdlc and design patterns are used to SAP BI/BW
    Please could you suggest , whether we are have to use in BI/BW
    thanks
    Babu

    Hi Babu,
    SAP BI/BW project also has got the standard project life cycle steps. Whenever you are working on a SAP BI/BW implementation project it starts from
    Requirement Gathering -
    > Blueprinting -
    > High level and detailed design -
    > Implementation -
    > Unit Testing -
    > Integration Testing -
    > Go live.
    Regards,
    Durgesh.

  • How do I 'call' external instance methods?

    I want to send a message from a Controller to another Class  to execute a method.  Inside the controller, I typed my message:     
                    [[MemoryContent]  PopulateMemory];
    What I think I am doing here is telling it to go to the MemoryContent class and execute the method called PopulateMemory.  The compiler insists that I make PopulateMemory into a class method.  But when I do that, I cannot deal with the instance methods and instance variables that I need.  What am I missing?

    Assuming you are following recommended Cocoa naming conventions, the fact that MemoryContent has an initial cap means it is a class, not an instance of a class. So the compiler error is correct. If you want to use an instance method, first create an instance of the class, then call the method on the instance.
    Your method name PopulateMemory should probably not have an initial cap.
    So you would typically see something like this.
    MemoryContent *memoryContent = [[MemoryContent alloc] init];
    [memoryContent populateMemory];
    Of course if the class instance already exists, don't create another one. Instead get a reference to the existing instance.

  • How to study design pattern?

    I have learn java for nearly a year and want to know more about design pattern.Fundemanetal instances of basic design pattern are appriciated.Thanks for your answer.

    The most famous book on patterns is :
    Design Patterns: Elements of Reusable Object-Oriented Software. Gamma et. al.
    You should start there if you are interested in the subject.
    There are tons of books since then on the subject. There is a list at
    http://hillside.net/patterns/books/

  • Get/set methods

    I've been programming in java for a while now, but just recently i started wondering about something. Doesn't get/set methods that contain no other code defeat the point of encapsulation? i.e
    public void getXxx() {
    return xxx;
    But now to the important question. Does the javac compiler inline get/set methods and if yes, how does it work around the private access to the data members?

    yes you are right. first all variables should be private (there are some cases where protected is useful). that being hte case, all access methods do is expose the way this class does its storage. and will break if that changes. for example, a rectange using int for width and height, has corresponding setWidth( int ), getHeight() etc. now the author of the class changes int to a Point. now there should only be get/setPoint and the previous should be removed. this changes the API and breaks code using this class.
    Lets say one keeps the setWidth etc as 'doing no harm', then the question is why does one need this? commonly used in eg
    setWidth( getWidth() + 10 );
    to lenghten the width.
    A better way is to capture this need in the messaging system. therefore have a method:
    widenBy( int w ) {
    width += w;
    notice this way, when changing the private width variable from int, to Point, to Long or any other, does not break code. there is no need to tidy up the access methods either.
    classes that have no behaviour are often created to group variables together and passed along for convenience. These are not strictly classes. Then why not have variables public and save the method calls to access methods. Having access methods does not make it more OO. These 'classes' should be defined as inner classes of the enclosing class.
    I've been programming in java for a while now, but
    just recently i started wondering about something.
    Doesn't get/set methods that contain no other code
    defeat the point of encapsulation? i.e

  • Class methods vs. Instance methods

    When shall we use class methods instead of instance methods , and vice versa?
    By going through the Java Tutorial, it only says the following.
    A common use for static methods is to access static fields....
    I am definitely sure that class methods aren't just exist for accessing static fields of a class.
    PS. I understand that instance methods belong to the object that is instantiated and class methods belong to the class itself.

    Jay-K wrote:
    JoachimSauer wrote:
    P.S.: I wouldn't call them "class methods". They are called static methods in Java. It helps to stay with the common, widely-used terminology.Thanks, its good to know what the norms are.
    but i wonder why the Java Tutorial states it clearly "Class Methods" over here [http://java.sun.com/docs/books/tutorial/java/javaOO/classvars.html|http://java.sun.com/docs/books/tutorial/java/javaOO/classvars.html]
    Because strictly speaking that's what they are. They belong to classes, rather than instances of classes. The world-at-large, though, has found that term to be a bit ambiguous, especially when discussing fields - it's not uncommon to see instance variables referred to as "class variables" by newbies - so it's kind-of self-corrected.

  • Regarding  design pattern

    Hi,
    This is swapna,
    I don�t have any idea about design patterns, plz.anybody help me
    regarding this, where I can get relevant information about design patterns
    Thanks in advance
    With regards
    Swapna.M

    Check http://hillside.net/patterns/onlinepatterncatalog.htm or http://dmoz.org/Computers/Programming/Methodologies/Patterns_and_Anti-Patterns/ for a catalog of online resources about patterns!
    Or google for design patterns

Maybe you are looking for

  • IPhone 5s - Microphone During Calls

    I received my new iPhone 5s today and have encountered an issue. When in the phone app, no one is able to hear me during calls. If I switch to speaker mode however, my voice will be picked up. I've also tested with Siri, and my voice is being picked

  • Power supply get very hot!

    I just bought a Pavilion dv6-6c35dx laptop and have noticed that the power supply gets really really hot, to the point that it scares me and I disconnect the laptop. Does anyone has the same problem?

  • Reinstalled itunes onto new hard drive....

    so i did exactly that, but now all my purchased songs wont play and a thing comes up and says "this computer is unauthorized to play [song]" and i have to log in and buy it again. is there a way i can reregister my itunes account to my new drive, or

  • Windows 8 Smart File Association Concept

    I have a feature for providing to Microsoft. See the following: We know Windows 8 tries to integrate the desktop and the touch interfaces into one OS. However, I think Microsoft forgets to update "Windows File Association," accordingly. For example,

  • Delivery of my iPhone 4s

    I just ordered my iphone 4s today 10-10-11. My confirmation  says that the expected delivery is not until 10/21/11. When I went into my Verizon store on Friday, The rep said that as long as I put my pre-order in before Wednesday, I would be able to r