Constructor / inheritance / encapsulation issue

Please consider this code:
public class Main {
  public static void main(String[] args) {  new BBB();  }
    public static class AAA {
        private int x;
        AAA() {  foo();  x = 123; }
        public void foo() { println("AAA::foo()"); }
    public static class BBB extends AAA {
        BBB() { super(); }
        public void foo() { println("BBB::foo()"); }
}The result is that the constructor in AAA invokes BBB's foo(), which violates encapsulation. I would just like to ask:
Invoking public/protected instance methods in the constructors of non-final classes is absolutely forbidden, right?
I am not asking why that happens. Rather, I just want to confirm the answer is "yes", it is forbidden. Or, if there are cases when it is ok, I am interested in learning them. Doing more that initializing instance variables in a constructor seems intriguing. But doing so could create weird situations (as in AAA's constructor) where you can access the private variable "x" of AAA and then invoke the BBB's foo().
ps: the "users online" and "guests online" forum statistics always equal zero.

dpxqb wrote:
abillconsl wrote:
dpxqb wrote:
Please consider this code:
The result is that the constructor in AAA invokes BBB's foo(), which violates encapsulation.Why does it violate encapsulation? BBB is a subclass of AAA, not just any class.So I design class AAA.
AAA's constructor requires that AAA's foo() be invoked to initialize.
AAA cannot control the behavior of BBB.
BBB subclasses AAA, and overrides foo().
If BBB's foo() does not invoke super(), AAA cannot initialize and thus neither can BBB.
I see more what you're talking about. Well first of all you don't have foo() invoking super() you have B() doing it - small point but worth getting straight. I never said, and didn't mean that your code was desireable BTW ... I said it's understandable and a good learning devise. Two other posters gave you good advice as to what to do about it. I'll give you another. make foo() private instead of public. There is no reason to show all your implementation code to everyone and good reasons not to. If foo() should not be called by anything but the ctor or AAA, then hide it. There is not reason that I can see to override that method either. AAA should be initialized only by AAA, and BBB by BBB. So you call foo instead aaaInitialize() and foo in BBB bbbinitialize.
Further, in the AAA constructor, a private variable is accessed "x", and then in the next line a method of a subclass is invoked. This blurs the boundary between what is hidden by the super class and exposed by a subclass (breaking encapsulation).
I would just like to ask:
Invoking public/protected instance methods in the constructors of non-final classes is absolutely forbidden, right?No it's not forbidden at all.The super class looses the ability to initialize itself. It becomes dependent on subclass behavior which breaks encapsulation.
I am not asking why that happens. Rather, I just want to confirm the answer is "yes", it is forbidden. Or, if there are cases when it is ok, I am interested in learning them.You should do a Topeka on the subject.ok.
Doing more that initializing instance variables in a constructor seems intriguing.
It's done all the time. For example, in the constructor you might all methods like: "createAndBuildGUI()", which would build the graphics part of a desktop app - instead of doing all that code directly in the one constr method. Just one example. IDE's like Eclipse do things like this.
But doing so could create weird situations (as in AAA's constructor) where you can access the private variable "x" of AAA and then invoke the BBB's foo().This is not wierd - it's designed to work like this.I just don't get it. A super class should never be allowed to invoke subclass's methods. The super class has no idea what the subclass's methods would do, so how could this be a reliable way to code? A class that invokes protected/public methods in the constructor is fragile and breakable. A concrete class should always be able to initialize itself regardless of what subclasses do.
As jschell hinted, I totally lost focus on what a "constructor" is suppose to do: just initialize the object and get it ready to roll, and nothing more. no behavior. thanks.

Similar Messages

  • Constructor Inheritance Question

    Here's a quote from the Java Tutorials at http://java.sun.com/docs/books/tutorial/java/javaOO/objectcreation.html :
    "All classes have at least one constructor. If a class does not explicitly declare any, the Java compiler automatically provides a no-argument constructor, called the default constructor. This default constructor calls the class parent's no-argument constructor, or the Object constructor if the class has no other parent. If the parent has no constructor (Object does have one), the compiler will reject the program."
    In order to fully understand this concept, I created two classes: a ClassParent and a ClassChild.
    public class ClassParent
        public static void main(String[] args) {
           ClassParent tester = new ClassParent();
    public class ClassChild extends ClassParent
        public static void main(String[] args) {
            ClassChild child = new ClassChild();
    }Both classes compiled successfully, which raised the following question:
    I understand that the ClassParent default constructor calls the Object's no-argument constructor.
    Does the ClassChild also call the Object's constructor once it realizes that the ClassParent does not have a no-argument constructor?
    And a somewhat non-related question:
    Seeing how ClassParent calls Object's no-argument constructor if it does not have one of its own, does it also extend the Object class?
    Edit: After running the following code, I realized that the answer to my last question is yes:
    public class ClassParent
        public static void main(String[] args) {
           ClassParent tester = new ClassParent();
           boolean test = tester instanceof Object;
           System.out.println(test);
    }Edited by: youmefriend722 on May 26, 2008 1:54 PM

    youmefriend722 wrote:
    I think I'm getting a basic grasp now but want to make sure that I'm not misunderstanding anything.
    Constructor inheritance:
    If a no-argument constructor is invoked but one isn't declared in that class, the superclass's no-argument constructor will be invoked. Well, sort of. If you invoke a constructor that doesn't exist, you get an error. Keep in mind that the invocation and the constructor may both be automatically supplied by the compiler, and that the compiler won't automatically create a no-arg constructor for a class if you define any constructors for that class.
    So if you don't define any constructors in a class, then a no-arg one is created automatically (at compile time) and (at runtime) when you instantiate that class, that no-arg constructor will try to invoke the superclass's no-arg constructor.
    But suppose you do define a constructor, one that takes an argument. Then if you try to invoke a no-arg constructor on that class, you'll get an error, and the superclass's no-arg constructor won't be invoked (because the error happens first).
    If the superclass does not have a constructor, then the superclass's superclass's constructor will be invoked.No. That never happens. Every class has a constructor (although it might have permissions which make it inaccessible, which is a whole other issue we'll worry about later).
    If the superclass does have a constructor but doesn't have a no-argument constructor, then there will be a compile-time error.Only if you try to invoke the no-arg constructor, which might happen implicitly. For example, if you write a superclass with a 2-arg constructor, and you write a subclass with a 1-arg constructor, and the 1-arg subclass's constructor invokes the superclass's 2-arg constructor, then there's no problem, even though in this example, the superclass doesn't have a no-arg constructor.
    Constructors in general:
    In every constructor, the superclass's no-argument constructor will be invoked if the none of the superclass's constructors are explicitly invoked.Yeah, I think that's right.

  • Constructor inheriting

    Can we inherit a constructor of the base class in the derived class.
    Please help.
    Shravan

    You can always write a constructor of your own, and call the super class constructor:
    public Dummy(int dummy) {  // Constructor for class Dummy which
                                // extends a class with a constructor which takes one int
        super(dummy);
    }/Kaj

  • JPA mixed inheritance strategy issue

    Table : A, b
    Class : A, B, C
    @Entity
    @Table(name="A")
    @Inheritance(strategy=InheritanceType.JOINED)
    @DiscriminatorColumn(name="type")
    abstract Class A
    @Entity
    @Table(name="B")
    @DiscriminatorValue("B")
    @PrimaryKeyJoinColumn()
    Class B extends A
    @Entity
    @DiscriminatorValue("C")
    Class C extends A
    From A - B its *@Inheritance(strategy=InheritanceType.JOINED)* and from A - C its *@Inheritance(strategy=InheritanceType.SINGLE_TABLE)* by default. When I try to run some test Toplink doesn't identifies class C as mixed strategy but expects C to have its own table as the super class A is specified with Joined strategy. Not sure how else would mixed strategy work !
    Any help would be greatly appreciated.
    Tx
    K

    Hello,
    My understanding is that all classes should use the inheritance strategy defined in its parent class - there is no way to have two strategies used on a single parent class.
    If you are aiming to get 3 classes (A, B and C) to use two tables (A, B) you might instead try specifying the root (A) to use SINGLE_TABLE. B will then automatically have an entry in Table A, and Class B can then be defined to use the B table as well by adding the @SecondaryTable(name="B") annotation to it, specifying the joincolumn if the primary key field names are different. A and C will then only use Table A, B will use Table A for inherited attributes and join to Table B - be sure to explicietly define the table to be used in any mappings on B that you wish to use Table B, otherwise I believe Table A will be assumed as it is the primary table.
    Best Regards,
    Chris

  • Extending a class, its constructor inherited ?

    class a extends JFrame
    xxxxxxxx
    public void a()
    xxxxxxxxxx
    class someclass
    a myA = new a();
    ================
    there is a constructor -> JFrame(String title) in JFrame.
    when i create an instance of this class a this way which extends JFrame, do i overwrite the constructor JFrame(String title) ? what if i want to have a constructor that i can use to create the instance of a this way ->
    a myA = new a("my title")
    how should i do it? and as for a good java programmer, what is the best and most efficient way ?
    thank you

    hi,
    class a extends JFrame
    xxxxxxxx
    public void a()
    super();
    public void a(String title)
    super(title);
    class someclass
    a myA = new a("My Title");
    Phil

  • Private - encapsulation or inheritance (but not both)

    Suppose that your class has some internal computation or logic that it performs, and that you wish to encapsulate this in a method that can not be called by other classes.
    You provide public methods that filter, format, or somehow modify the input and/or output of this encapsulated method.
    class pseudoCodeClass {
    private coreLogic(Objects inputs) {
    Maybe some complicated math stuff;
    Or password stuff;
    Or pay out functionality for a slot machine;
    return(stuff);
    public getUserData(inputs) {
    format/check the inputs;
    coreLogic(inputs);
    format the output;
    Now, how do you leveradge the power of OO inheritance to extend the internal logic that you encapsulated? If you make the interal logic private, then it's encapsulated, but you lose the power of OO inheritance, or you can make it protected and lose the encapsulation. I thought an OO language was supposed to have encapsulation and inheritance, not encapsulation or inheritance. (And, yes I realize that there is some techincal sense in which private methods are still inherited, but I'm talking about the general OO concept of inheritence where it includes overriding or extending.)
    Suppose you want to:
    class pseudoCodeSubclass extends pseudoCodeClass {
    private coreLogic(inputs) {
    super.coreLogic(inputs);
    additional more specific code; // The whole point of OO inheritence
    You can't extend super.coreLogic through your access to super.getUserData because it does all sorts of filtering and formating that is not a part of the internal logic that you wish to extend/override. And, providing other more public accessor methods to the core logic just defeats the encapsulation.
    I have seen many discussions of this, but none with any answers to my satisfaction. One line of answers is that you don't want encapsulated stuff to be part of your object's contract. Some times people with this sort of answer even suggest coppying the code from the super class into the subclass. People with this sort of answer don't seem to even want the option to use inheritence because of the obligation that might go with it. But without the option of inheriting encapsulated logic, they are forced to either use cut and paste (in an OO language that seems wrong to me) or to abandon encapsulation all together. Being forced into those 2 extreems doesn't seem to me like it would simplify future support of your class, and future support seems to be the primary point of the contract line of response.
    The way some people argue about this, I amost want to say - Look! In C you can encapsulate everything you want, and never have to worry about inheritance. (But you still shouldn't have to cut and paste.)
    Another line of response that I have seen is that private methods should only be used in breaking up code that would have gone into a single method. In other words, the private methods aren't really 'units of program logic' they are just a mater of organizational convenience. So if you had:
    public oneBigMessyMethod() {
    100 lines of A;
    100 lines of B;
    100 lines of C;
    you could maintain it as:
    public oneBigMessyMethod() {
    a();
    b();
    c();
    private a() {
    100 lines of A;
    private b() {
    100 lines of B;
    private c() {
    100 lines of C;
    I agree private works well in this situation. Presumably since a(), b() and c() are divided up for convenience rather than because of distinct logical function, you wouldn't want to extend just a() with inheritance. But this also seems to dodge the question. Just because sometimes you might not want encapsulated functionality to be available for extention, does not mean that you would never want it. I think that I'd also have to disagree with the permise that encapsulation is only for hiding stuff that is just a convention of convenience. The main point of encapsulation is to hide information or functionality. If encapsulation is only used for the convenient breakdown of your primary functionality, then all of your primary functionality is public, package or protected. That does make it inheritable. But, now all of the primary functionality is a part of the contract for that class.
    Is there an answer to this issue that does not ignore the value of either encapsulation or inheritance?
    There is one way that I can see to do exactly what I think should be possible. That is to put only classes from the same hierarchy in a package. Then both package and protected effectively provide encapsulation with the ability to inherit (and you do still have the option to use private or final if there is a case where you want to disable inheritence).
    What I'd like to know is - What do people actually do? In the real world, do people:
    1) use private + cut and paste
    2) use package/protected + self discipline
    Where 2 is that you drop encapsulation within your package but then excercise self dicipline and just don't call/access stuff that you intend to be for that class only...
    Or is there some 3rd thing that I'm missing? I've tried to think how maybe you could design your objects in such a way that you'd never need to inherit/extend something that you would also want to encapsulate. But I just don't see how that's possbile.
    So, what do people do?
    Chris

    First of all, you have got to understand that I am not
    suggesting that Private and Final should be changed or
    removed from java. It looks to me like there should
    be an additional access option (and there was
    originaly).
    I understand that if a class inherits something, it
    could expand the access or put public accessor methods
    around it. Obviously with ultra sensitive code this
    would be a nightmare. So private and final are very
    important. But if the very possibility of another
    class expanding a given level of access is a reason
    for not even having that level of access, then why do
    we have package and protected?
    There are a great number of places in common coding where that access does restrict usage in a usable way.
    >
    If the only re-use of your code that you allow is
    through the public interface, what do you even need an
    OO language for? Just for the polymorphism and a
    different way to organize your code?
    Not sure what you mean by that but see below.
    But as I've said. I've seen this whole thing argued a
    number of times. But what I haven't seen is any
    explanation of what people who take the poslition that
    I'm taking actually do when they write code. Because
    I can sit here with a bunch of other people and say 'I
    wish Java had this or that'. And then of couse a
    bunch of people will resopond and say 'no that's dumb'
    or 'I don't see the point'. But at the end of the
    day, Java still is what it is. So, arguing about what
    it 'should be' is not going to effect how anyone
    codes.
    Sure it can. That is why java now has assert().
    So, what I started out wanting to know is how people
    actually code. Particularly people who wish that Java
    had a subclass only access modifier.
    I don't wish that.
    Perhapse I should also be asking about how things are
    done by people who see this level of access as
    unnececary. How they code is easy enough to
    understand. Making everything that is not intended to
    be accessed by any other class private is easy enough
    to do. But what would be interesting to know is how
    do you design your classes to leveradge inheritance if
    you do this. Maybe there is some way of desinging
    around ever having 'internal functionality' that you
    would want to extend and I'm just not getting it.
    There are three broad classifications of objects.
    1. Those that only use encapsulation
    2. Correct inheritence hierarchies
    3. Incorrect inheritence hierarchies
    The first of those, which I consider most classes to fall into, do not need this.
    The third area occurs when programmers use inheritence as a convenience mechanism to propogate behavior amoung different classes rather than using encapsulation as should be done. They don't understand the difference between "is-a" relationships (design) and coding convienence. I would estimate that at least 50% of existing object hierarchies fall into this area. Since in this case the entire design is wrong an extension is not needed.
    The second area is the only correct area where this might be needed. Since I personally believe that very few classes belong in hierarchies and this proposed extension would only be useful in a sub fraction of those. Since the correct usage is so small I don't think it would be useful addition to the language.

  • ActiveSync issue for a single user

    Hello,
       We are finishing a migration to Exchange 2010 from 2007.  Everything is connecting fine so far for all users except one.  This user is the owner of the company, and a long time ago, like more than 20 years, instead of creating a copy
    of the Built-in administrator account, he renamed it for himself.
       Anyway, he is the only user that is unable to connect via ActiveSync.  The event viewer on the Exchange server says "User '[email protected]' cannot synchronize their mobile phone with their mailbox because Exchange ActiveSync has been
    disabled for this user.   But of course, in the EMC, it says that he is enabled, and I ran the command in the Management Shell to ensure it was enabled. 
       I did some research and found that checking the Include Inheritable Objects is supposed to help with this, but I did that and it still didn't work.  It also became unchecked again after a while. 
        I'm not sure where to go next at this point.  Every other mailbox on the server ActiveSyncs no problem.  It's just this one.
    Thanks.

    Create a new AD account for him that isn't a member of any built-in admin level groups and disconnect the existing mailbox and reconnect it to the new AD Account.
    Mail Enabling the admin account is just not going to work well in 2010/2013 or beyond and its not a good security practice to use it except for elevated tasks. Hopefully the owner appreciates that.
    You could mess with the AdminSDHolder stuff and allow the ActiveSync partnership to be created but I highly recommend against that.
    http://eightwone.com/2011/08/31/exchange-activesync-and-inheritable-permissions-issue/
    Twitter!:
    Please Note: My Posts are provided “AS IS” without warranty of any kind, either expressed or implied.

  • Constructors and Private attributes

    I'm developing an object which parse a string in tokens.
    I need to override a Constructor, I need extend functionality of system constructor.
    Another issue is I need to use private attributes in my object.
    Somebody knows a way to do this?
    I appreciate some help
    Best Regards

    Daniel,
    Which release are you using? With Oracle9i R2, you can use 'user-defined constructors' (http://otn.oracle.com/docs/products/oracle9i/doc_library/release2/appdev.920/a96594/adobjadv.htm#1009574). 'Private' attribute is not supported yet. If I know more about your usage scenario, there may be a workaround.
    Regards,
    Geoff
    I'm developing an object which parse a string in tokens.
    I need to override a Constructor, I need extend functionality of system constructor.
    Another issue is I need to use private attributes in my object.
    Somebody knows a way to do this?
    I appreciate some help
    Best Regards

  • Thesis on abap

    hi,,
    i am pursuing a course in advance software technologies and have to do a project for four months..
    i want to do a thesis , can you please suggest me some topics on which i can do thesis, considering that i only am familiar with ABAP..
    please oblige me..
    thankyou,
    regards,
    Abbas.
    How about:
    "Comparative system resources required for single row lookups on hashed internal tables vs vs binary searches for single rows in sorted internal tables"
    What's interesting here are the time/space issues required for the overhead of the hashed setup, and whether these negate the performance improvement of the hashed lookup (factoring in the time to sort the non-hashed table, of course.)
    regards
    djh
    However, can any help me how to go about doing this,, r there any documents available for doing this..
    ur tips and hints wouldly surely help me..
    pls reply,
    regards,
    abbas

    This information may help your thesis.
    The programming language like ABAP (Advanced Business Application Programming) is specially created for developing SAP applications. ABAP Objects is a new concept in R/3 System and you can find its two distinct meanings, one stands for the entire ABAP runtime environment and the other represents the new object-oriented generation of this language. 
    by Arindam Ghosh
    Introduction
    Object
    Classes
    Features of Object Orientation
    Uses of Object Orientation
    ABAP Objects
    About Classes
    Attributes
    Methods
    Events
    Features
    Conclusion
    Introduction
    The object orientation can be defined as a problem-solving method in which the software solution reflects objects in the real world. Therefore, a comprehensive introduction to object orientation would go far beyond the limits of this introduction to ABAP Objects as a whole.
    Object
    An object can be defined as a section of source code that contains data and provides services. The attributes of the object are formed by the data. The services are known as methods (also known as operations or functions). Typically, it is seen that the methods operate on private data (the attributes, or state of the object), which is only visible to the methods of the object. Thus, the attributes of an object cannot be changed directly by the user, but by the methods of the object only. This guarantees the internal consistency of the object.
    Classes
    The classes are very important, as they describe the objects. From a technical point of view, the objects are runtime instances of a class. One can create any number of objects based on a single class in theory. Each instance (object) of a class has a unique identity and its own set of values for its attributes.
    Features of Object Orientation
    Encapsulation
    According to this property, objects restrict the visibility of their resources (attributes and methods) to other users. Every object has an interface which plays a very important role. It determines how other objects can interact with it. It is found that the implementation of the object is encapsulated, which means that it is invisible outside the object itself.
    Polymorphism
    According to this property, identical (identically-named) methods behave differently in different classes. Object-oriented programming contains constructions, which are called interfaces. They enable you to address methods with the same name in different objects. The implementation of the method is specific to a particular class, though the form of address is always the same.
    Inheritance
    According to this property, one can use an existing class to derive a new class. The data and methods of the super class are inherited by the derived classes. However, they can overwrite existing methods and add new ones.
    Uses of Object Orientation
    The object-oriented programming is quite useful in many ways. It has various advantages, some of which are mentioned below.
    Since object-oriented structuring provides a closer representation of reality than other programming techniques, complex software systems become easier to understand.
    In object-oriented system, it should be possible to implement changes at class level, without having to make alterations at other points in the system. This reduces the overall amount of maintenance required.
    The object-oriented programming allows reusing individual components through polymorphism and inheritance. 
    In this system, the amount of work involved in revising and maintaining the system is reduced as many problems can be detected and corrected in the design phase.
    To achieve these goals, the followings are required:
    Object-oriented programming languages: The efficiency of object-oriented programming depends directly on how object-oriented language techniques are implemented in the system kernel.
    Object-oriented tools: Object-oriented tools allow you to create object-oriented programs in object Oriented languages. They also allow you to model and store development objects and the Relationships between them.
    Object-oriented modeling: The object-orientation modeling of a software system is the most important, most time-consuming, and most difficult requirement for attaining the above goals. These designs involve more than just object-oriented programming and logical advantages that are independent of the actual implementation are provided by it.
    ABAP Objects
    ABAP Objects is a new concept in R/3 System and you can find its two distinct meanings --- one is for the entire ABAP runtime environment and the other represents the new object-oriented generation of this language.
    The Runtime Environment
    ABAP Objects, for the entire ABAP runtime environment, are an indication of how SAP has, for sometime, been moving towards object orientation. Object-oriented techniques have been used exclusively in system design. The ABAP language did not support these techniques earlier.
    The ABAP Workbench will allow creating R/3 Repository objects in this regard. These objects are programs, authorization objects, lock objects, customizing objects, and so on and so forth. By using function modules, one can also encapsulate functions in separate programs with a defined lnterface. The Business Object Repository (BOR) allows you to create SAP Business Objects for internal and external use.
    The Object-Oriented Language Extension
    ABAP Objects support object-oriented programming. The ABAP Objects is a complete set of object-oriented statements, which has been introduced into the ABAP language. This object-oriented extension of ABAP builds on the existing language and is fully compatible with it.
    The Object Orientation (OO), also known as the object-oriented paradigm, is a programming model that unites data and functions in objects. You can not only use ABAP Objects in existing programs, but also work with and use a conventional ABAP in new ABAP Objects programs. The rest of the ABAP language is primarily intended for structured programming, where data is stored in a structured form in database tables and function-oriented programs access and work with it.
    Moreover, we should know that the object-oriented enhancement of ABAP is based on the models of Java and C++. It is compatible with external object interfaces such as DCOM and CORBA. The implementation of object-oriented elements in the kernel of the ABAP language has considerably increased response times when you work with ABAP Objects. Some other objects, such as SAP Business Objects and GUI objects, which are already object-oriented by themselves, are also benefiting from being incorporated into ABAP Objects.
    About Classes
    The classes are templates for objects. An abstract description of an object is the class. You could say it is a set of instructions for building an object. The attributes of objects are defined by the components of the class, which describe the state and behavior of objects.
    Local and Global Classes
    In ABAP Objects, classes can be declared either globally or locally. You define global classes and interfaces in the Class Builder (Transaction SE24.} in the ABAP Workbench. In the R/3 Repository, they are stored centrally in class pools in the class library. In an R/3 System, all of the ABAP programs can access the global classes. The local classes are defined within an ABAP program. Local classes and interfaces can only be used in the program in which they are defined. When you use a class in an ABAP program, the system first searches for a local class with the specified name. If it does not find one, then it looks for a global class. Apart from the visibility question, there is no difference between using a global class and using a local class.
    However, there is a significant difference in the way that local and global classes are designed. If you are defining a local class that is only used in a single program, then to define the outwardly visible components so that it fits into that program is usually sufficient. On the other hand, global classes must be able to be used anywhere. Since the system must be able to guarantee any program using an object of a global class, it can recognize the data type of each interface parameter and then certain restrictions are applied at the time of defining the interface of a global class.
    Defining Local Classes
    Local classes consist of ABAP source code, where the ABAP statements CLASS...ENDCLASS are enclosed. A complete class definition consists of the following parts, a declaration part and, if required, an implementation part. It is found that the declaration part of a class  IMPLEMENTATION
    ¦
    ENDCLASSThe implementation part of a class actually contains the implementation of all methods of the class because it is observed that the implementation part of a local class is a processing block. Therefore, subsequent coding itself is not a part of a processing block and is not accessible.
    Class Structure
    A class contains components where each component is assigned to a visibility section. Moreover, the classes implement methods. Let us define these components one by one.
    Components
    This is the first component and is declared in the declaration part of the class. The components define the attributes of the objects in a class. When you define a class, each component is assigned to one of the three visibility sections. This defines the external interface of the class and all of the components of a class are visible within the class. All components are in the same namespace. This means that all components of the class must have names that are unique within the class. There are two kinds of components in a class:
    One that exists separately for each object in the class.
    The other consists of those that exist only once for the whole class, regardless of the number of instances.
    Attributes
    It is the instance-specific components, which are known as instance components. The static components are those components that are not instance-specific. The classes can define the following components in ABAP Objects.
    The attributes are internal data fields that can have any ABAP data type within a class. The state of an object is determined by the contents of its attributes. One kind of attribute is the reference variable. The reference variables are also very important as they allow you to create and address objects. Reference variables can be defined in classes, which allow you to access objects from within a class.
    Instance Attributes
    The instance-specific state of an object is defined by the contents of instance attributes. They can be declared by using the DATA statement.
    Static Attributes
    The contents of static attributes define the state of the class that is valid for all instances of the class. The static attributes exist once for each class. It is declared using the CLASSDATA statement. They are accessible for the entire runtime of the class. All of the objects in a class can access its static attributes. If you change a static attribute in an object, then the change is visible in all other objects of the class.
    Methods
    The methods are internal procedures that define the behavior of an object in a class. They can access all the attributes of a class. This allows them to change the data content of an object. They also have a "parameter interface," whose role is to help the users by supplying them with values when calling them and receiving values back from them. The private attributes of a class can only be changed by methods in the same class. The definition and parameter interface of a method is similar to that of function modules. Using the following processing block, you define a method
    ENDMETHODIn the same way as in other ABAP procedures (subroutines and function modules), you can declare local data types and objects in methods. You call the following methods by using the CALL METHOD statement.
    Instance Method
    You can declare instance methods by using the METHODS statement. They play a very important role as they can access all of the attributes of a class and can trigger all of the events of the class.
    Static Methods
    You can declare static methods by using the CLASS-METHODS statement. They are important and can only access static attributes and trigger static events.
    Special Methods
    Apart from normal methods, there are two special methods which you call using CALL METHOD. These are called CONSTRUCTOR and CLASS _CONSTRUCTOR. They are automatically called when you create an object (Constructor) or when you first access the components of a class (CLASS _CONSTRUCTOR).
    Events
    Objects or classes can use events to trigger event handler methods in other objects or classes. One method can be called by any number of users in a normal method call. When an event is triggered, any number of event handler methods can be called. Until runtime, the link between the trigger and the handler is not established. The calling program determines the methods that it wants to call in a normal Method call and it must exist. With events, the handler determines the events to which it wants to react. It is not necessary that for every event there has to be a handler method registered.
    With the help of RAISE EVENT statement, the events of a class can be triggered in the methods of the same class. You can declare a method of the same or a different class as an event handler method for the event . Events have a similar parameter interface to methods, but only have output parameters. These parameters are passed by the trigger (RAISE EVENT statement) to the event handler method, which receives them as input parameters.
    Using the SET HANDLER statement, the link between trigger and handler is established dynamically in a program. The trigger and handlers can be objects or classes, depending on whether you have instance or static events and event handler methods. When an event is triggered, the corresponding event handler methods are executed in all registered handling classes.
    Features
    Encapsulation
    The three visibility areas (public section, protected section, private section) are the basis for one of the important features of object orientation, Encapsulation. You should take great care in designing the public components and try to declare as few public components as possible when you define a class. Once you have released the class, the public components of global classes may not be changed.
    Public attributes are visible externally and form a part of the interface between an object and its users. If you want to encapsulate the state of an object fully, then you cannot declare any public attributes. Apart from defining the visibility of an attribute, you can also protect it from changes using the READ-ONLY addition.
    Inheritance
    Inheritance allows you to derive a new class from an existing class. It is done by using the INHERITING FROM addition in the statement:
    CLASS . The new class is called the subclass of the class from which it is derived. The original class is called the superclass of the new class. It contains the same components as the superclass if you do not add any new declarations to the subclass. However, in the subclass only the public and protected components of the superclass are visible. The private components of the superclass are not visible though they exist in the subclass. You can declare private components in a subclass that have the same names as private components of the superclass. It is seen that each class works with its own private components. The another point that we note is that methods which a subclass inherits from a superclass use the private attributes of the superclass and not any private components of the subclass with the same names.
    The subclass is an exact replica of the superclass if the superclass does not have any private visibility section. However, you can add a new component to the subclass because it allows you to turn the subclass into a specialized version of the superclass. If a subclass is itself the superclass of further classes, then you can introduce a new level of specialization.
    Polymorphism
    Reference variables are defined with reference to a superclass or an interface defined with reference to it can also contain references to any of its subclasses. A reference variable defined with reference to a superclass or an interface implemented by a superclass can contain references to instances of any of its subclasses, since subclasses contain all of the components of all of their superclasses and also convey that the interfaces of methods cannot be changed. In particular, you can define the target variable with reference to the generic class OBJECT.
    Using the CREATE OBJECT statement, when you create an object and a reference variable typed with reference to a subclass then you can use the TY PE addition to which the reference in the reference variable will point.
    A reference variable can be used by a static user to address the components visible to it in the superclass to which the reference variable refers. However, any specialization implemented in the subclass cannot be addressed by it.
    Depending on the position in the inheritance tree at which the referenced object occurs, you can use a single reference variable to call different implementations of the method. This is possible only if you redefine an instance method in one or more subclasses. This concept is called polymorphism, in which different classes can have the same interface and, therefore, be addressed using reference variables with a single type.
    Conclusion
    I have explained object orientation which is such an important aspect in SAP. The discussion began with the features of Object Orientation and includes the runtime environment, the language extension, the classes and the class components. Apart from that I have also discussed for new first time readers event handling, inheritance encapsulation and polymorphism.

  • Java program HELPPPP!!!!!

    Hello, I'm very new to Java programming, and well I'm taking Computer Science as my major, and I need a little help to this program:
    You will develop an inheritance hierarchy of classes to enhance your understanding of inheritance, encapsulation, and polymorphism.
    All classes developed must be complete including:
    appropriate symbolic constants
    appropriate data fields
    constructors (default, complete, and, if appropriate, partial)
    accessor methods
    mutator methods
    standard methods inherited and overridden from Object:
    boolean equals(Object other)
    String toString()
    problem specific methods
    The project involves working with washers. A Washer is a circular metallic disc with its circular center removed. As such, the relevant data fields for a washer are:
    the outer diameter (OD) of the larger circle
    the inner diameter (ID) of the smaller circle
    the thickness of the disc
    When constructing or mutating these data fields remember that they need to be validated such that all fields are greater than zero and the outer diameter must be larger than the inner diameter (use helper methods for validation so that the code only appears once).
    In addition to the Washer class you will also need to define two derived classes based on the type of metal used for the washer. These will be BrassWasher and SteelWasher. Brass has a density of 8.4 g/cm3 while steel has a density of 7.8 g/cm3 (both of these numbers are approximate since both metals are alloys and their densities depend on the composition of the alloys). The densities should be defined as symbolic constants in the appropriate derived classes.
    The problem specific methods needed are:
    double volume()
    double weight()
    These should be placed in the appropriate classes.
    The main program (in class TestWashers) will create an array of Washer instances (generate reasonable values for the inner and outer diameters and thickness of the washers as well as the material types by using random numbers (see Math.random())) (discussed in class and look up the documentation). The program will then compute the total weight of the collection of washers as stored in the array. The program will display the list of washers (i.e., by using toString() for each array element) and then the total weight of the whole collection of washers (properly annotated).
    My question is what should I put in the Washer class? you know the parent class. Because I'm confuse on the boolean equals(object other) and String toString(), and the double volume and double weight.
    and how to do the Math.random()?
    This is the program that my teacher told us to do, but I'm having problems on how to start.
    Thanks.

    Please change your code tags. Even you must see that they aren't working.
    You can do this by changing your curly braces to square braces[code]
    Your code is still editable so you can do this without having to repost the whole thing.
    regarding toString: if you wanted a quick way to represent what data a Washer object contains, what would this one line string look like?  Model your toString() after this.
    regarding your equals: what object variables need to be all equal for two washers to be the same type?  Write an equals method to match that.  Note that equals must be passed an object as its parameter.  So the first thing you must do is check to make sure that the passed parameter object is in fact a Washer object (use instanceOf for this).  If not, return false.
    Edited by: Encephalopathic on Oct 1, 2008 7:28 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Report margin on export to PDF

    Hi,
    I am using SQL Server 2008, Project Server and Report Builder 3.0 and have just inherited an issue.
    I have two reports:
    D_Subreport: This report contains all logic and detail
    D_Report: A report referencing D_Subreport as a Subreport
    In one of our SharePoint project sites we run the D_Report, this has a dropdown parameter which allows multi selection. This works as expected - the report displays in the browser with no margins as per the designed report, on export to PDF it has a margin
    set, I'm not sure where this is set(?), but it looks good to us.
    The problem, when running the D_Subreport from another Project site (no multi select as it runs under the context of the project site) the reports displays as expected in the browser, however on export to PDF there are
    NO margins. It seems as though having a containing parent report creates margins within the PDF, running Subreport directly does not.
    How do I get it to display using the same margins as D_Report?
    Thanks

    Thanks.
    My problem was that one report had margins and the other didn't - Plus it turns out a Subreport's margins are ignored by the parent report. I had to create a duplicate report in our scenario.

  • Crystal Reports 8.5 & 9 Via Web Application

    Post Author: bearie
    CA Forum: Older Products
    I have inherited an issue with a proprietary web based
    application and Crystal Reports 8.5 & 9. Someone a few years ago wrote a .dll file that would that a
    requested Crystal Report, via the web application, and the report would be
    displayed in edible Word Rich Text format.
    The Crystal Report contained parameters that were passed to the reports
    via .asp or SQL.
    Both the person who wrote the .dll and the source code of
    the .dll are long gone.
    This process worked great until about a month ago.  Now when a report is edited with Crystal
    Reports or a new report created and accessed using the same methods the report
    will not launch or launches with out updating the data in the report. 
    We believe the issue has to do with one of the many
    Microsoft updates and patches that were coming out about a month ago.
    Up to now I have been a report developer, creating the SQL
    and reports and turning them over to the u201Cprogrammers".  To make a long story short u2013 the u201Cweu201D is now
    me, and I do not have a clue the best route to take to resolving the issue.
    Please any ideas and / or suggestions will be greatly
    appreciated. 
    --if there is a better forum to post this, please let me
    know.
    Thanx!

    Post Author: bearie
    CA Forum: Older Products
    Since there have been no replies - I am guessing what we need to have done cannot work with the versions of Crystal we are currently using. If we were to update to the latest Crystal - can this be done.  Need to find out before I try to convince my company to upgrade. Thanx

  • Static class functions: PLS-00801: internal error [phd_get_defn:D_S_ED:LHS]

    Any ideas why this would generate an internal error - referring to a static class function in that class constructor's parameter signature?
    Test case (on 11.2.0.2) as follows:
    SQL> create or replace type TMyObject is object(
      2          id      integer,
      3          name    varchar2(30),
      4 
      5          static function DefaultID return integer,
      6          static function DefaultName return varchar2,
      7 
      8          constructor function TMyObject(
      9                  objID integer default TMyObject.DefaultID(), objName varchar2 default TMyObject.DefaultName()
    10          )return self as result
    11  );
    12  /
    Type created.
    SQL>
    SQL> create or replace type body TMyObject is
      2 
      3          static function DefaultID return integer is
      4          begin
      5                  return( 0 );
      6          end;
      7 
      8          static function DefaultName return varchar2 is
      9          begin
    10                  return( 'foo' );
    11          end;
    12 
    13          constructor function TMyObject(
    14                  objID integer default TMyObject.DefaultID(), objName varchar2 default TMyObject.DefaultName()
    15          )return self as result is
    16          begin
    17                  self.id := objId;
    18                  self.name := objName;
    19                  return;
    20          end;
    21 
    22  end;
    23  /
    Type body created.
    SQL>
    SQL> declare
      2          obj     TMyObject;
      3  begin
      4          obj := new TMyObject();
      5  end;
      6  /
    declare
    ERROR at line 1:
    ORA-06550: line 0, column 0:
    PLS-00801: internal error [phd_get_defn:D_S_ED:LHS]If the static class functions are removed from the constructor and applied instead inside the constructor body, it works without error. Likewise you can call the constructor with the static class functions as parameters, without an internal error resulting.
    SQL> create or replace type TMyObject is object(
      2          id      integer,
      3          name    varchar2(30),
      4 
      5          static function DefaultID return integer,
      6          static function DefaultName return varchar2,
      7 
      8          constructor function TMyObject(
      9                  objID integer default null, objName varchar2 default null
    10          )return self as result
    11  );
    12  /
    Type created.
    SQL>
    SQL> create or replace type body TMyObject is
      2 
      3          static function DefaultID return integer is
      4          begin
      5                  return( 0 );
      6          end;
      7 
      8          static function DefaultName return varchar2 is
      9          begin
    10                  return( 'foo' );
    11          end;
    12 
    13          constructor function TMyObject(
    14                  objID integer default null, objName varchar2 default null
    15          )return self as result is
    16          begin
    17                  self.id := nvl( objId, TMyObject.DefaultID() );
    18                  self.name := nvl( objName, TMyObject.DefaultName() );
    19                  return;
    20          end;
    21 
    22  end;
    23  /
    Type body created.
    SQL>
    SQL> declare
      2          obj     TMyObject;
      3  begin
      4          obj := new TMyObject();
      5  end;
      6  /
    PL/SQL procedure successfully completed.
    SQL>
    SQL> declare
      2          obj     TMyObject;
      3  begin
      4          obj := new TMyObject(
      5                          objID => TMyObject.DefaultID(),
      6                          objName => TMyObject.DefaultName()
      7                  );
      8  end;
      9  /
    PL/SQL procedure successfully completed.
    SQL> Had a quick look on support.oracle.com and did not turn up any specific notes dealing with the use of static class functions in the parameter signature of the constructor. Known issue? Any other workaround besides the one above?

    Hi,
    there is a bug: "Bug 8470406: OBJECT INSTANCE CREATION FAILS WITH ERROR PLS-00801 IN 11GR1", it shows the behaviour in 11g but not in 10.2. It gives exactly the symptoms you also see, move it to the body and it works. But there is no solution/patch given.
    Herald ten Dam
    http://htendam.wordpress.com

  • Is using Parallel Hint /*+PARALLEL */  good or bad?

    Hi,
    I am facing problem in using /*+ PARALLEL */ hint in SQL Query its taken long time to execute.
    Is using PARALLEL Hint degrades performance?
    The Table FCT_TABLE is having PARALLEL ( DEGREE DEFAULT INSTANCES DEFAULT ) clause.
    We are using parallel hint as SELECT /*+ PARALLEL(FCT_TABLE 2)
    Any help will be needful for me.
    Thanks and Regards

    user598986 wrote:
    We have noticed the following from the Server:
    1.The Disk I/O is showing 0 always during the time of Execution of the Query.
    2.The I/O Adapter is showing 700%.What is the o/s and version? Do you use any virtualisation? What storage system do you use? What RAID levels, if any? And how did you monitor these results?
    Note that the physical I/O layer is not part of the database layer. From the database layer you typically address I/O issues with
    - logical design (e.g. normalise data so that there's a single copy of the data to maintain and thus less I/O)
    - physical design (e.g. use partitioning, IOTs, clusters, indexes and so on to facilitate less I/O to process data)
    - parallelise (use multiple processes to perform large I/O scans to address some of the inherited latency issues when doing I/O)
    - reduce I/O (e.g. by truncating a table or partition instead of deleting it, using CTAS, design s/w that only needs to make a single pass through a data set, etc)
    From the database app level you have no control over where the data is stored, how it is stored and cached. So, as PL/SQL or app developer, your primary concern should be the amount of I/O your data model and app needs - as that is something you can and do control. And not worry about the physical implementation of the I/O layer. As that should be the concern of the sys admin and DBA of that platform.

  • Regarding object oriented concept

    hai i am a student..
    i just want to know the opnions of everybody...
    considering todays object oriented language what will be the future language features? (for example if u consider c language which is basis for c++.. it has polymorphism ,inheritance, encapsulation. etc features..which are not found in c).. if the future language design from c++ or java ,what will be its new concepts ?. i mean will be the new features..
    do anybody find any flaws in todays oo language ..do any body have new ideas on basic concepts of oo design to be improved
    i know this is very crazy.. i just want to know your ideas..

    And the cross posting multi posting fiesta continues.
    http://forum.java.sun.com/thread.jspa?threadID=692984&tstart=0
    sr1_reddy stop posting this garbage please.

Maybe you are looking for

  • Where is Adobe Media Encoder CC

    I think after an update, Adobe Media Encoder CC crashes on start-up. It actually crashed my Mac which never ever done it before. I tried to update and found out that Media Encoder CC is no longer listed as an app. Is there an application that replace

  • Calendar colour changes

    My work calemdar suddenly changed from Green To Purple which clases with onother canendar. Unable to get it back. This seems to be a problem for many people. Any answers??

  • Virtual User Minutes in Visual Studio Online Account Not Updating

    Dear Team, I have conducted a LoadTest connecting to my VSO account and even after completing the test under Resource Usage section I'm not able to see my VUM(Virtaul User Minute) usage changing. Its always 0. Please help me with it. Regards, Divin

  • E 72 gps mute?

    Hi, I have a e72 nokia running gps with no sound.. no words. Volumen is full but no sound.... What can I do? regards

  • Server 2012 Three Teir PKI Deployment

    Hi I've been test building this on the bench prior to deployment. I have; 1x Offline Root CA 1x Online Intermediate Subordinate Enterprise CA 2x Issuing Enterprise Subordinate Enterprise CA's 1x Issuing Enterprise Subordinate Enterprise CA (will be i