Constructor Vs. Method Qustion

Hi,
i learn now about constructor in Abap and my question is ,
what is the advantage  and disadvantage of using constructor oo,that i can build method that do the same  action
e.g.
Regular Method:
    METHODS: set_attributes IMPORTING
             im_name TYPE string
             im_planetype TYPE saplane-planetype,
             display_attributes.
Constructor :
    METHODS: constructor IMPORTING
    im_name TYPE string
    im_planetype TYPE saplane-planetype,
    display_attributes.
in the constructor i use:
  CREATE OBJECT r_plane
    EXPORTING
      im_name      = 'LH_Barlin'
      im_planetype = 'a321'.
and in Method :
CREATE OBJECT r_plane.
  r_plane->set_attributes( im_name = 'LH_usa' im_planetype = 'bbb' ).
and both commend do the same :
Regards

First,  you should post these questions in the ABAP Objects forum.
Anyway, you use the constructor to force certain actions when the instance is created.  If you as designer of the class require that two attributes be set, then making them obligatory parameters ensures that an object can't be instantiated without those parameters being given some values.  You could include some validation in the constructor as well to make sure that the values are valid.
If you don't put them in a constructor, you are relying on future developers - possibly even yourself - remembering to set those parameters after they've created.
One other advantage - it's one line of ABAP instead of three!
As ever though, which is better comes down to what specifically you're trying to do.  It is usually better programming practice to leave as little to luck and remembering, as possible.
matt

Similar Messages

  • Constructor, accessor methods

    Hi,
    I have read some codes examples from book, one code made direct references to instance variables from inside client
    implementations (e.g., emp.employeeid) - instead of using accessor
    methods. And the book actually suggests using accessor methods.
    Why it is better to use constructors, accessor, and mutator methods on private instance variables?
    I am not very clear on this concept, why accessor or mutator methods are better ?
    I think the book implies emp.getEmployeeid() is the better approach, am I right ? but why ?
    Thanks in advance !
    Phil

    Thanks ! But, I can do something like this..
    class Department {
    Employee emp = new Employee();
    int id = emp.employeeid;
    It looks ok, isn't it ?Only if employeeid is a public variable. If it is marked private in the Employee class then it won't work.
    Another reason for using accessor and mutator methods is so that the author of the class can have control over how the private variables are used and to trap bad values.
    If the variables are left public then the data contained in them could be corrupted by another class manipulating them. Making the variable private and having a mutator method allows more control over what gets stored in the variable.

  • Multiple constructors for methods

    I have to write a method that takes both ArrayList and array so i'm assuming that i'll need something like multiple constructors for classes but i can't seem to find anything about this anywhere. Is it possible?

    Uhm, then you don't need multiple constructors, just overload your method.
    [http://java.sun.com/docs/books/tutorial/java/javaOO/methods.html]

  • For which one is the priority? constructor or method ?

    Hi
    if i have A constructor and a method and both of them working on the same variable, so for which one is the priority ?
    Message was edited by:
    scrolldown

    whichever one gets there first. no, really. and a
    constructor is just a methodAu contraire, mon fr?re!
    Constructors are not methods, because unlike methods,
    they are not
    even technically members of a class.
    http://java.sun.com/docs/books/jls/third_edition/html/
    classes.html#8.8
    <quote>
    Constructor declarations are not members. They are
    never inherited and therefore are not subject to
    hiding or overriding.
    </quote>I stand corrected there, then. aren't they described by the same bytecode instructions, though? I know that when using, say, BCEL, constructors and initializers are generated as methods. whatever, I'm obviously barking up the wrong tree there

  • Method qustion

    Hi,
    i watch code that use method and i dont understand it.
    gx_table ?= cl_abap_typedescr=>describe_by_data( itab )
    1. describe_by_data is a method so why i don't use it like fm
    with call Method with import and export .
    2. what is this ?=  sign .
    Regards

    HI
    gx_table ?= cl_abap_typedescr=>describe_by_data( itab )
    here when you are dealing with classes and objects as you asked
    describe_by_data is method of the class cl_abap_typedecr and
    you are casting the result to the gx_table.
    [Check This Link|Re: Dynamically create reference attribute]
    Re: Read data element of a field in a program
    Regards
    Gangadhar

  • Error while calling a super class public method in the subclass constructor

    Hi ,
    I have code like this:
    CLASS gacl_applog DEFINITION ABSTRACT.
      PUBLIC SECTION.
        METHODS:
                create_new_a
                   IMPORTING  pf_obj       TYPE balobj_d
                              pf_subobj    TYPE balsubobj
                              pf_extnumber TYPE string
                   EXPORTING  pfx_log_hndl TYPE balloghndl
                   EXCEPTIONS error
    ENDCLASS.
    CLASS gacl_applog IMPLEMENTATION.
      METHOD create_new_a.
        DATA: ls_log TYPE bal_s_log.
      Header aufsetzen
        MOVE pf_extnumber TO ls_log-extnumber.
        ls_log-object     = pf_obj.
        ls_log-subobject  = pf_subobj.
        ls_log-aluser     = sy-uname.
        ls_log-alprog     = sy-repid.
        ls_log-aldate     = sy-datum.
        ls_log-altime     = sy-uzeit.
        ls_log-aldate_del = ls_log-aldate + 1.
        CALL FUNCTION 'BAL_LOG_CREATE'
             EXPORTING
                  i_s_log      = ls_log
             IMPORTING
                  e_log_handle = pfx_log_hndl
             EXCEPTIONS
                  OTHERS       = 1.
        IF ( sy-subrc NE 0 ).
          MESSAGE ID      sy-msgid TYPE sy-msgty NUMBER sy-msgno
                  WITH    sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
                  RAISING error.
        ENDIF.
      ENDMETHOD.
    CLASS gcl_applog_temp DEFINITION INHERITING FROM gacl_applog.
      PUBLIC SECTION.
        DATA: log_hndl   TYPE balloghndl READ-ONLY
            , t_log_hndl TYPE bal_t_logh READ-ONLY
        METHODS: constructor
                   IMPORTING  pf_obj       TYPE balobj_d
                              pf_subobj    TYPE balsubobj
                              pf_extnumber TYPE string
                   EXCEPTIONS error
               , msg_add      REDEFINITION
               , display      REDEFINITION
    ENDCLASS.
    CLASS gcl_applog_temp IMPLEMENTATION.
      METHOD constructor.
        CALL METHOD create_new_a
               EXPORTING  pf_obj       = pf_obj
                          pf_subobj    = pf_subobj
                          pf_extnumber = pf_extnumber
               IMPORTING  pfx_log_hndl = log_hndl.
        IF ( sy-subrc NE 0 ).
          MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                  WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
                  RAISING error.
        ENDIF.
      ENDMETHOD.
    A public method of Super class has been called from the constructor of the sub class. we are getting the syntax error :
    ' In the constructor method, you can only access instance attributes, instance methods, or "ME" after calling the constructor of the superclass…'
    Can you please suggest how to change the code with out affecting the functioanlity.
    Thank you ,
    Lakshmi.

    Hi,
    Call that method by instance of Subclass.   OR
    SUPER-->method.
    Read very useful document
    Constructors
    Constructors are special methods that cannot be called using CALL METHOD. Instead, they are called automatically by the system to set the starting state of a new object or class. There are two types of constructors - instance constructors and static constructors. Constructors are methods with a predefined name. To use them, you must declare them explicitly in the class.
    The instance constructor of a class is the predefined instance method CONSTRUCTOR. You declare it in the public section as follows:
    METHODS CONSTRUCTOR
            IMPORTING.. [VALUE(]<ii>[)] TYPE type [OPTIONAL]..
            EXCEPTIONS.. <ei>.
    and implement it in the implementation section like any other method. The system calls the instance constructor once for each instance of the class, directly after the object has been created in the CREATE OBJECT statement. You can pass the input parameters of the instance constructor and handle its exceptions using the EXPORTING and EXCEPTIONS additions in the CREATE OBJECT statement.
    The static constructor of a class is the predefined static method CLASS_CONSTRUCTOR. You declare it in the public section as follows:
    CLASS-METHODS CLASS_CONSTRUCTOR.
    and implement it in the implementation section like any other method. The static constructor has no parameters. The system calls the static constructor once for each class, before the class is accessed for the first time. The static constructor cannot therefore access the components of its own class.
    Pls. reward if useful....

  • Difference between constructor & Methods if any ?

    In the below code I use the constructor ConstructorShirt1('M') to pass the value of M to the class ConstructorShirt1, but why do we have to do this, instead can we not just use a method and write the same thing in a method.
    class ConstructorShirt1Test {
         public static void main (String args[]) {
    ConstructorShirt1 constShirt = new ConstructorShirt1('M');
    char colorCode;
              colorCode = constShirt.getColorCode();
    System.out.println("Color Code: " + colorCode);
    class ConstructorShirt1 {
    private int shirtID = 0; // Default ID for the shirt
    private String description = "-description required-"; // default
    // The color codes are R=Red, B=Blue, G=Green, U=Unset
    private char colorCode = 'U';
    private double price = 0.0; // Default price for all items
    private int quantityInStock = 0; // Default quantity for all items
    public ConstructorShirt1(char startingCode) {
    switch (startingCode) {
    case 'R':
    case 'G':
    case 'B':
    colorCode = startingCode;
    break;
    default:
    System.out.println("Invalid colorCode. Use R, G, or B");
    public char getColorCode() {
    return colorCode;
    } // end of class
    So I am not clear what is the difference between constructor and methods if any ? or if not when to use a constructor and when to use a method.
    I would be glad if somebody throws light on this topic.
    PK

    There shouldn't be any confusion on this one... a constructor is meant to create an instance of the class. It can also set the state of its member variables in the process, like the constructor you are using. The same can also be done by a method.
    Wouldn't make much of a difference for simple programs, but this is more pertinent when it comes to designing classes. Like if the developer using the class needs to know what all states he has to set before he needs to do anything useful, then it is better to provide a constructor with some arguments for doing that.

  • Academic Question about Classes Method and Constructor

    Given the similarity between the Constructor class and the Method class, why don't they have a common super class for the methods they have in common that are unique to them?

    sledged wrote:
    jschell wrote:
    sledged wrote:
    I've found that the most common reason for invoking a constructor or method through reflection is because you don't know what you need until runtime, commonly because what you want can vary based on context, or is otherwise being specified external to the bit of code that uses reflection. Not true. The fact that I don't need it until runtime never means I don't know what I need.Never? Then your experiences with the reflection API have been different than mine. Either that or I wasn't very clear. Let's take Apache Commons BeanUtils;
    It doesn't matter how you access a class. You can't use it unless
    1. You have a goal in mind
    2. That object in some way fulfills that goal.
    3. You know how that object fulfills that goal.
    And as I already pointed out you can't use a JFrame for a JDBC driver. Simple as that. Nor can I create a new class that implements, for example, ProC (Oracle method to embed access into C code) using my own idiom despite that it provide database access. It MUST match what jdbc expects.
    Sometimes it's not even clear before runtime whether a constructor's needed or a method.
    I disagree. That isn't true in any OO language.Perhaps not out the box, but it can be true when using certain tools built from the OO language. Let me continue using the Spring framework as an example. It does not know whether to use a method or a constructor to instantiate any bean defined in the XML configuration metadata until that XML file is read and it determines whether or not a given bean definition has the "factory-method" attribute. The XML file in not read until runtime, therefore with any given bean defined therein, Spring does not know until runtime whether to use a constructor or method.Not apt at all.
    As I already said those are two different idioms. Spring supports them because they are used to solve different problems not because they wish constructors didn't exist.
    >
    The basis of OO is the "object". You can't have a method without the object in the conceptual OO model. (And in Smalltalk that is always true.)
    True, but one may not always care how the "object" is provided. When the method [Properties.load(InputStream)|http://java.sun.com/javase/6/docs/api/java/util/Properties.html#load%28java.io.InputStream%29] is called, it isn't going to care whether the InputStream argument was instantiated by one of the FileInputStream constructors, or if it came from a [URL.openStream()|http://java.sun.com/javase/6/docs/api/java/net/URL.html#openStream%28%29] method call. It'll work with either regardless of their respective origins.
    That of course has nothing to do with anything. Unless you are suggesting that construction in any form should not exist.
    A factory is not a constructor.I'm not saying it is. I'm just pointing out a number of the similarities between the two.
    So? There are many similarities between RMI and JDBC but that doesn't mean that they should be the same.
    With your argument you can claim that construction doesn't exist because any method, regardless of intent, that uses 'new' would eliminate the need for construction. And that isn't what happens in OO languages.I wouldn't claim that construction doesn't exist in any OO language. But I do know that in ECMAScript construction exists on the basis of whether or not a method is called with the 'new' operator. So in ECMAScript a single method can also be a constructor.
    And in C++ I can entirely circumvent the object construction process. Actually I can do that in JNI as well.
    I would still be a bad idea.
    >
    They are not interchangable.Normally, no, but with a high enough level of abstraction, they can become interchangeable. Again, the Spring framework is a great example. It doesn't care if a method or a constructor is used, and it won't know which one has been chosen until runtime. I don't even think Spring checks the return type of a method, so you could use a void return type method. (Although I don't know what that would buy you because the bean would always be set to null, but still...)
    No.
    Based on that argument every possible programming problem could be solved by simply stating that one must implement the "doit()" method. One just need to generalize it enough.
    Different APIs exist because there are in fact differences not because there are similarities.
    Over generalization WILL lead to code that is hard to maintain. Actually generalization itself, even when done correctly, can lead to code that is actually more complex.
    Because construction is substantially different than calling a method. In all OO languages.Yes, construction is different, but the actual call to a constructor and a method is only syntactically different with the presence of the 'new' operator. With reflection the difference is between calling Method.invoke() and Constructor.newInstance(), and, as I mentioned earlier, there's enough similarity between the two methods that they could be called by a single method specified by a common super class.Which does not alter the fact that the process of achieving the result is fundamentally different.

  • Constructor question?

    I am working on a class called Firm and it has an array of employee objects as its data field. Its constructor has an array of employee objects as its parameter: it initializes the data field array by copying references from the parameter array in a loop. Its main method creates one or two HourlyEmployee objects and one or more exemptEmployee objects. Then it calls setPay for one HourlyEmployee object and one ExemptEmployee objects and prints the results. Then it calls methods setPay and toString for these two objects (calling println, annotate this part of processing so that the output is readable).
    What I have so far is, Employee being an abstract class that has a Constructor, and methods setPay(), getPay(), and toString. Subclasses HourlyEmployee and ExemptEmployee each with their own constructors and methods getPay() and setPay() along with toString() methods.
    Currently this is what I have for code for my Firm class:
    public class Firm
    private Employee[] empObj;
    Firm(Emp[] empObj)
    for(int i = 0;i<empObj.length;++i)
    arrObj=empObj;
    }Does my constructor have an array of employee objects as its parameters? Do I need to create an Object array[] arrObj?

    if Firm's constructor is being passed an Employee array, then just save that reference.
    public class Firm
      private Employee[] empObj;
      public Firm(Emp[] empObj)
        this.empObj = empObj;
    }Alternatively, you may wish to copy the parameter so that changes to the original (made outside by the guy who passed it to you, for example) don't affect it. In that case, change Firm's constructor to do this:
    this.empObj = new Employee[empObj.length];
    for (int i = 0; i < empObj.length; ++i)
      this.empObj[i] = empObj;
    // or, you may even want to "deep-copy" it like this, if you created
    // a "copy-constructor" or "clone" method:
    this.empObj[i] = new Employee(empObj[i]);
    //or
    this.empObj[i] = (Employee) empObj[i].clone();

  • XSLStylesheet constructor deprecated, which to use?

    I keep getting:
    Warning(91,44): constructor XSLStylesheet(oracle.xml.parser.v2.XMLDocument, java.net.URL) in class oracle.xml.parser.v2.XSLStylesheet has been deprecated
    But the docs(using latest release of Oracle9i and JDeveloper9i) says nothing about this constructor being deprecated and which to use instead.
    Also the method setParam(name,value) is deprecated in the same class.
    If someone knows which constructor and method to use, please post a reply!
    Best regards
    Christer

    Use this documentation:
    http://otn.oracle.com/docs/tech/xml/xdk_java/doc_library/Production9i/doc/java/javadoc/index.html
    Regards :
    Rob

  • [ADF-11.1.2.2] Method on Custom declarative Compoment load

    Hi,
    I made a custom declarative component. Through Attribute, Parent page is passing some values but I need to process that attribute variable and display the result on page.
    For that I need to have a method which will get called before component is rendered completely so that I can process attribute value and generate result which can be displayed on component output.
    I tried different combination, like getting attribute value using ADFUtil.evaluateEL in back end bean constructor, Set method of binding of one of field on component... but every time I get null value. But if I have button with ActionListener on bean, I get proper value on click on component button.
    I also have enabled Custom Component Class while creating new component which creates class with RichDeclarativeComponent as parent class. But Still I am unable to get help from parent methods for my requirement. I override different methods but none of them are called on page load through which I can fetch attribute values...
    Can you please let me know how to call a method on component load on parent page which when called, can fetch the passed value of Attribute variable ?

    Hi,
    as you want to display this on the component UI, use e.g. an af:outPutText and bind its value property to a managed bean setter/getter pait. In the getter method query the attributes you receive from the consuming page
    Frank

  • Constructor ? best practice

    Hi folks,,
    this is my piece of my code. i had a doubt on the  initializing the variable inside constructor or else before the constructor.?
        private java.net.URL xl = Thread.currentThread().getContextClassLoader().getResource("z.xml");
      private static Logger log;   
      sSessionBean csb = (sSessionnBean)Util.getMBean("ssbean");
      public cWrapper()
    super();  
    log = Logger.getLogger(sWrapper.class.getName());
    consider x1,csb variable these two variable declared and initialized that place itself...
    consider log variable this is declared in the appropriate declaration section and initialized in constructor.
    which is best to practice to initialize.?
    thanks

    consider log variable this is declared in the appropriate declaration section and initialized in constructor.
    No - it isn't. You defined 'log' as static.
    private static Logger log; 
    Therefore 'log' is initialized when the class itself is initialized. Since your code does not assign a value the variable will be initialized to 'null'.
    Be careful that you understand the difference between 'initialization' and 'assignment'; they are two related, but different, things.
    See section '8.3.2. Initialization of Fields' in the Java Language Spec
    http://docs.oracle.com/javase/specs/jls/se7/html/jls-8.html#jls-8.3.2
      If the declarator is for a class variable (that is, a static field), then the variable initializer is evaluated and the assignment performed exactly once, when the class is initialized (§12.4.2). 
    In the constructor you are merely assigning a new, non-null, value to the 'log' variable.
    this is my piece of my code. i had a doubt on the  initializing the variable inside constructor or else before the constructor.?
    which is best to practice to initialize.?
    The decision of whether to initialize instance variables and, if so, where to physically place those initial assignment statements is up to you and should depend on when you need the instance variables to have a value.
    The physical placement of the assignment might be before, within, or after (which you didn't mention) any particular constructor and may be performed within a method of the class or instance.
    See this example code from the Java Language Spec showing an assignment statement physically after the constructor:
    http://docs.oracle.com/javase/specs/jls/se7/html/jls-8.html#jls-8.3.2.3
    class Test2 {
      Test2() { k = 2; }
      int j = 1;
      int i = j;
      int k;
    You have over-simplified the possibilities:
    1. There can be both static and instance variables - statics are ALWAYS initialized exactly once but can then, if not declared 'final' have new values assigned later in constructors or methods.
    2. Variables can be declared as 'final' - in which case they will be initialized and given a value only once.
    3. There are often multiple constructors - not just the one you have in your example. So an instance variable that needs the same common value regardless of the constructor being used would be given that value OUTSIDE of any constructor. It would be unnecessary, and poor practice, to repeat the variable assignments in every constructor.
    Each of the constructors could also, if required, assign a different initial value to an instance variable.
    4. Different class instances may need the variables initialized to different values. This is related to the previous example. A constructor may take parameters whose value is used to make an assignment to a variable. The constructor code may determine which variables to assign values to and what values to assign.
    5. Some instances may seldom need a variable to be initialized and when they do will initialize it within a method. For those use cases neither the variable declaration nor any of the constructors will provide an initial value.
    An often ask question related to yours is whether to physically put variable declarations for a class at the start of the class file or at the end. IMHO that is more of a personal preference; I don't believe there is a 'best practice'. An org will usually specify one or the other as part of their coding standards that are to be followed.

  • Help realllllllllllllllllllllllllly needed - rectangle methods ... please

    k i know this is going to be alot but i feel like i need to post all the details of the assignment for it to be easier for people to understand. the length of this is probably going to deter some people but hopefully some nice people will take the challenge lol...its beginners stuff for AP:
    1. A default Rectangle object is specified in the constructor with the x, y, and width and height set to 0.
    2. A Rectangle object is specified in the constructor with the left and right edges of the rectangle at x and x + width. The top and bottom edges are at y and y + height.
    3. A Rectangle object is specified that is a copy of an existing Rectangle.
    4. Methods getXPos( ), getYPos( ), getWidth( ), and getHeight( ) return the x, y, and height and width of the Rectangle, respectively.
    5. A method getDirection( ) returns the current orientation of the DrawingTool.
    6. Methods setXPos( ), setYPos( ), setWidth( ), and setHeight( ) set the x, y, and height and width of the Rectangle respectively to the value of each method?s double parameter.
    7. A method setDirection( ) sets the current orientation of the DrawingTool.
    8. A method getPerimeter( ) calculates and returns the perimeter of the Rectangle.
    9. A method getArea( ) calculates and returns the area of the Rectangle.
    10. A method draw( ) displays a new instance of a Rectangle object.
    11. A method drawString( ) displays String at the specified x and y coordinates of the drawing area.
    # The methods draw( ), drawString( ), and setDirection( ) make use of existing DrawingTool methods. Refer to the DrawingTool specifications that you printed out in week two for details on DrawingTools methods.
    # Write a testing class with a main method that constructs a Rectangle, rectA, and calls setDirection( ), setWidth( ), and draw( ) for each Rectangle created. It is recommended that the changes in orientation and width of each successive rectangle in the spiral be calculated using the getDirection( ) and getWidth( ) methods. For example, if the increment for each turn is given by turnInc and the decrease in size of the rectangle is given by widthDec, then successive calls to the following:
    rectA.setDirection (rectA.getDirection() - turnInc);
    rectA.setWidth (rectA.getWidth() - widthDec);
    rectA.draw ( );
    would draw each ?spoke? of the rectangular spiral.
    # Construct another Rectangle , rectB, that is a copy of the original rectA. Draw the rectangle in the upper left corner of the drawing area. Label the width, height, perimeter, and area of the rectangle. The resulting image will be similar to the one shown below:
    so far this is wat i have: class Rectangle
        private static DrawingTool pen = new DrawingTool(new SketchPad (500,500));
        private double myX;      
        private double myY;        
        private double myWidth;
        private double myHeight;
        private double perimeter;
        private double area;
        private double myDirection;
        //Default constructor
        Rectangle()
        Rectangle(double x, double y, double width, double height)
            myX = x;
            myY = y;
            myWidth = width;
            myHeight = height;
        Rectangle (Rectangle rect)
        public double getPerimeter()
            return 2 * (myWidth + myHeight);
        public double getArea()
            return myWidth * myHeight;
        public void draw()
            pen.up();
            pen.move(myX, myY);
            pen.down();
            pen.setDirection(90);
            pen.forward(myHeight);
            pen.turnRight(90);
            pen.forward(myWidth);
            pen.turnRight(90);
            pen.forward(myHeight);
            pen.turnRight(90);
            pen.forward(myWidth);         
        public void drawString (String str, double x, double y)
            myX = x;
            myY = y;
        public double getXPos ()
            return myX;
        public double getYPos ( )
            return myY;
        public double getWidth()
            return myWidth;
        public double getHeight()
            return myHeight;
        public double getDirection()
            return myDirection;
        public void setXPos(double x)
            myX = x;
        public void setYPos(double y)
            myY = y;
        public void setWidth(double width)
            myWidth = width;
        public void setHeight(double height)
            myHeight = height;
        public void setDirection(double distance)
            distance = myDirection;
    public class RectangleTest
        public static void main(String[] args)
            Rectangle rectA = new Rectangle();
            rectA.setDirection (rectA.getDirection() - turnInc);
            rectA.setWidth (rectA.getWidth() - widthDec);
            rectA.draw ( );//not sure how to use this set of code, was given to me.
    }any input always appreciated =)

    getDirection() is supposed to get the pen's direction. At the moment you are
    setting and getting your own value (myDirection) that has nothing to do with
    the pen.
    So I would write something like:public double getDirection()
        return pen.getDirection(); // <-- or something...
    }You will have to consult the DrawingTool's documentation to find out exactly what
    pen method you are after. setDirection() will be similar.
    (Notice - by the way - what you are doing here: when someone creates a
    Rectangle you are sort of "hiding" the drawing pen from them. You are letting
    them see and change the direction of the DrawingTool but nothing else
    like colour or thickness or whatever else a DrawingTool has.)
    You have to do two things - perhaps even before you change the
    get/setDirection() methods:
    (1) Write something in main() that will test what you've done so far.
    Ie use the setXXX() methods to set the width, height, position etc. Check
    that the getXXX() methods are returning the right values.
    Your tests will tell you if you're on the right track.
    If your code won't compile (and you can't figure out the compiler's message!)
    then you have a specific question to ask. Remember to say what the
    message is, and indicate what line it refers to.
    If your program compiles, but you get really weird and unexpected results -
    like is says a test Rectangle has an area of -42 - then, again you will have a
    specific question.
    (2) Go through the specifications carefully, and figure out which constructors
    and methods you have not implemented. If the meaning of the
    specifications are truely incomprehensible to you, you again have something
    specific to ask.
    Good luck.

  • Generated constructor in exception classes - ommitted textid in superclass

    Hi,
    debugging another program i stopped in the constructor of one of my own exception classes. Starring at the code one questoion arised
    method constructor.
    call method super->constructor
    exporting
    textid = textid
    previous = previous
    if textid is initial.
       me->textid = zcx_xi .
    endif.
    me->errortext = errortext .
    me->sysid = sysid .
    endmethod.
    First of all i would use
    if textid is *supplied*.
       me->textid = zcx_xi .
    endif.
    But this is not my question. If i'm raising this exception without supplying the textid the superclass is call with an initial textid, which is filled later pn with the predefined class named textid.
    If i'm raising this exception specifying the textid as
    raise exception type zcx_xi exporting textid = zcx_xi=>zcx_xi errortext = message.
    the super class will not get an intial textid but the predefined one.
    Both versions are working well delivering the errortext by the get_text( ) method in the catch branch.
    But... is there really no difference calling the super class with initial value or given value?

    It looks like there is no difference.
    This code replaces any existing TEXTID set by Super class when we don't pass any TEXTID.
    IF textid IS INITIAL.
       me->textid = CX_SY_ZERODIVIDE .
    ENDIF.
    If the code uses the attribute TEXTID (me->textid) instead of the importing parameter TEXTID, than it would make a lot difference.
    IF ME->textid IS INITIAL.   " Attribute TEXTID
       me->textid = CX_SY_ZERODIVIDE .
    ENDIF.
    I guess, we need some SAP Official response before going ahead.
    Regards,
    Naimesh Patel

  • Initiating variables with private constructor fails

    Goodday all,
    At the moment I'm working on a little class that reads the input from the console screen. The class looks like this (I omitted a few unrelevant methods):
    public class SomeClass {
      private static BufferedReader bin = null;
      // private constructor; another method (not shown here) returns an instance
      private SomeClass() {
        bin = new BufferedReader(new InputStreamReader(System.in));//somehow this doesn't work ??????
      //public method
      public final String readLine(String message) {     
              String feedback = "";
              try {
                   if(bin==null) say("variable bin is null"); //bin is indeed null, just don't know why
                   else feedback = bin.readLine();
              catch (IOException e) {
                   e.printStackTrace();
              return feedback;
    }Executing this code will result in output "variable bin is null". When I try debugging it, I see that the variable bin will remain null when the constructor is called.
    Placing the initiation of 'bin' in another method will make things work, but I want to know why it doesn't work in the constructor. It seems as a fair piece of code ;).

    private static BufferedReader bin = null;Why is it static?
    // private constructor; another method (not shown here) returns an instance
    private SomeClass() {
    bin = new BufferedReader(new InputStreamReader(System.in));//somehow this doesn't work ??????
    }'Somehow it fails?' It doesn't even compile!
    Executing this code will result in output "variable bin is null". When I try debugging it, I see that the variable bin will remain null when the constructor is called.Your constructor doesn't even compile, so I find it hard to believe it ever executed.

Maybe you are looking for

  • Obiee 11g - Formula between fixed date and variable date

    Need some advice please, I'm trying to modify a campaign report for Marketing so we can track over different periods of time. For example Start Date +7 days (all volume within this period) Start Date +28 days ( all Volume within this period) And so o

  • "artists" vs "compilations"

    Good day! Some of my music, by a single artist, shows up in my iPod in the "compilations" segment of my music files but not in the "artist" segment, where I would prefer to find these selection. How may I move artists from these albums into my "artis

  • How do i uninstall/remove photoshop cs3

    what is the best way to remove photoshop cs3? how do i uninstall a program? dragging it to trash doesnt remove everything. help!

  • Uninstall SAP BPC 7.0

    Hi all, I have problem uninstalling the SAP BPC 7.0 on Microsoft Platform. When I uninstall through Windows Add/Remove Component, the wizard stuck at the Removing Sample OLAP database? Any idea what am I missing out here? Is there a uninstall guide I

  • File Fields and ASP

    I have setup an htm page with a file field. We use asp to post data. Do I need any additional coding to make the attached files show up in the email? Here's the link: http://krontechnology.com/positions.htm Thanks.