Objective-C class without base class

I'm in doubt about the sense of letting a class to have no base class (neither NSObject nor Object).
I have observe that in this case you could not send messages to the object, so you can't use:
Point* p =[[Point alloc]init];
But you can use:
Point* p = (Point*) malloc(sizeof(Point));
And access attributes of the object:
p->x = 5;
Is there any other advantage of using classes in this way (instead of a C struct)? Why language designed allowed this feature?
Greeting: Fernando

I would guess that it is because of it's C roots. Essentially all objects in obj-c are C structs. There is nothing really preventing a person creating their own NSObject like root class and using that in their framework.

Similar Messages

  • Export for AS: Class vs Base Class

    when i export a movie clip for actionscript, what are the differences between Class & Base Class?  i see most tutorials change Base Class and leave Class as the name of the movie clip defined in the library.

    the main use of the base class is to extend it so many different classes can share it's functionality.
    but even when not needed as a super class, the base class is also helpful when you want to instantiate many different objects using code and you don't want to write/compile many different class files.
    if flash finds you failed to write a class file (for every class exported for actionscript), flash writes a default class files for you.

  • How to call derived class to base class

    Hello everybody,
    I create a GUi application in java swing. Now i want to navigate between the screen but the timing between the screen is very slow bcoz i imported the class from package to another package. Now i want to extends one package to another package to reduce the navigation time but it saying error bcoz i cant able to call my derived class to base class. if anyone know the answer for this please answer this immediately.
    If any other method is there to optimise the navigation time please tell me
    by
    (kamal)

    Sorry, I've got major difficulties understanding your query:
    I create a GUi application in java
    ication in java swing. ok
    Now i want to navigate between
    the screenwhat? switch screens? display a different dialog?
    but the timing between the screen is very
    slowtiming? do you mean the time it takes to display a different dialog?
    bcoz i imported the class from package to
    another package.how did you come to the conclusion that that is the reason for the slowness? Did you do any profiling or is this just guess-work?

  • Owner Class and Base Class ?

    hi,
    What is an Owner class and base class?
    thanks,
    Hanu

    Hi,
    the question is related to oracle java class or samething else?
    I dont understand your question.
    Regards,
    Tom

  • Can a derived class catch base class object

    can a derived class object catch a base class object
    e-g if i have a class
    class Test {
    // code
    }and
    class Test2 extends Test {
    }and lets say there is a method that return an object of Test (base class), so is it possible to write
    Test2 t=getTestObj(); // i-e subclass holding base class objectif its not.. how can we do so? so that derived class should hold base class object....

    sorry..
    here is how it goes
    i have a function a class
    public Test getObj() {
    // code
    }The constraint is that i cant change the implementation of this above function.
    Now when i call this function, it returns me a Test object. But i cant do
    Test t=getObj();because the Test class is written purely in java whereas i want to use write a new Test class that implements the same functionality [using the above given function] in JNI.
    so what i did, i created a new package [nativ] and created a class "Test" in that. But since i have to use the function that returns me Test and not "nativ.Test", so what i did, i inherited nativ.Test from "Test" so that the object might resolve the reference.
    So this is it.. that i cant modify the function and i need some way to do it.. plz reply

  • Set fields of derived class in base class constructor via reflection?

    Does the Java Language Specification explicitly allow setting of fields of a derived class from within the base class' constructor via reflection? The following test case runs green, but I would really like to know if this Java code is compatible among different VM implementations.
    Many thanks for your feedback!
    Norman
    public class DerivedClassReflectionWorksInBaseClassConstructorTest extends TestCase {
    abstract static class A {
        A() {
            try {
                getClass().getDeclaredField("x").setInt(this, 42);
            } catch (Exception e) {
                throw new RuntimeException(e);
    static class B extends A {
        int x;
        B() {
        B(int x) {
            this.x = x;
    public void testThatItWorks() {
        assertEquals(42, new B().x);
        assertEquals(99, new B(99).x);
    }

    why not just put a method in the superclass that the subclasses can call to initialize the subclass member variable?In derived classes (which are plug-ins), clients can use a field annotation which provides some parameter metadata such as validators and the default value. The framework must set the default value of fields, before the class' initializer or constructors are called. If the framework would do this after derived class' initializer or constructors are called, they would be overwritten:
    Framework:
    public abstract class Operator {
        public abstract void initialize();
    }Plug-In:
    public class SomeOperator extends Operator {
        @Parameter(defaultValue="42", interval="[0,100)")
        double threshold;
        @Parameter(defaultValue="C", valueSet="A,B,C")
        String mode;
        public void setThreshold(double threshold) {this.threshold = threshold;}
        public void setMode(String mode) {this.mode = mode;}
        // called by the framework after default values have been set
        public void initialize() {
    }On the other hand, the default values and other metadata are also used to create GUIs and XML I/O for the derived operator class, without having it instantiated. So we cannot use the initial instance field values for that, because we don't have an instance.

  • Extending class + accessing base class's children

    Hello.
    I'm trying to create a sort of info and tool panels for a project, similar to the ones on the Adobe Suite's products. They'll have a tab that you can double click to open or close them and the panel's title will be on this tab.
    So I created a MovieClip called MainPanel and inside it I placed a textfield called txtTitle and a rectangular MovieClip called mTab. I duplicated the MainPanel twice on the stage, called them PanelA and PanelB, and added individual elements to them, but kept the txtTitle and mTab.  I edited PanelA and PanelB's linkage options to link them to specific custom classes.
    First I created a base class for the MainPanel.
    package com.panels{
        import flash.display.MovieClip;
        import flash.events.MouseEvent;
        import fl.text.TLFTextField;
        public class MyPanel extends MovieClip {
            public function MyPanel ():void {
                txtTitle.mouseEnabled = false;
                mTab.doubleClickEnabled = true;
                mTab.addEventListener(MouseEvent.DOUBLE_CLICK, clickedPanel);
    And then the classes for Panel A and B, which extend the MainPanel.
    package com.panels{
        import com.panels.MyPanel;
        public class PanelA extends MyPanel {
            public function PanelA ():void {
    When I test the movie, I get an error saying "Access of undefined property txtTitle" (and the same for mTab). If I just link PanelA to the MainPanel class it all works - I got it to open, close, dragged it with the mouse... I can access mTab, txtTitle and anything else already on the stage. But if I extend the class, I no longer can. Does anyone know why this happens and the best way to get it to work? Thank you.

    Still didn't do the trick, I even tried building a project from scratch with just the classes I mentioned in my example and nothing else, and then a second version where I have all files on the same directory. Not sure if it might have something to do with this being for an AIR app.
    I have found a solution that seems to be working. My new MyPanel class:
    package com.panels{
        import flash.display.MovieClip;
        import flash.events.MouseEvent;
        import fl.text.TLFTextField;
        public class MyPanel extends MovieClip {
            private var _title:TLFTextField;
            private var _tab:MovieClip;
            public function MyPanel ():void {
                _title = MovieClip(getChildByName("txtTitle")); //If I don't cast the result as a MovieClip I get an error
                _tab = TLFTextField(getChildByName("mTab")); //Same for the TLFTextField
                _title.mouseEnabled = false;
                _tab.doubleClickEnabled = true;
                _tab.addEventListener(MouseEvent.DOUBLE_CLICK, clickedPanel);
    Still I'd like to understand why I need to go through these hoops so I don't make the same mistake again.

  • Base classes with Collection attributes

    I have a question. Suppose I have a base class A, an abstract base class
    to be exact, and subclasses B and C. Assume A has an attribute of
    Collection type, let's call it collectionImpl. Now I would like subclasses
    B and C to be able to have elements of different types along the lines of
    what I've outlined below.
    Strictly speaking, class A wouldn't have to be PC, since I primarily care
    of B and C but I wanted to show the structure.
    <class name="A" persistence-capable-superclass="A">
    <field name="collectionImpl">
    <collection element type="someType"/>
    </field>
    </class>
    <class name="B" persistence-capable-superclass="A">
    <field name="collectionImpl">
    <collection element type="someOtherType"/>
    </field>
    </class>
    So, how would one express this?
    Scott

    Understood. Now for bit more clarification. Given my earlier example, what
    if classes A, B and C implement the java.util.Collection interface. Does
    Kodo have in issue with that? I know Kodo has this ProxyCollection stuff
    but I don't really want to do that, nor do I think I really need to given
    what I'm trying to accomplish.
    The issue I'm having now is that the Kodo Enhancer is complaining that no
    element-type is declared when I have an attribute of class type B for
    example (implementing java.util.Collection) even though an element type is
    declared for the that actual Collection object held in the base class of B
    (A).
    <class name="A" requires-extent="false">
    <field name="impl">
    <collection element-type="SomeType"/>
    <extension vendor-name="kodo" key="ordered" value="true"/>
    </field>
    </class>
    <class name="B" persistence-capable-superclass="A"
    requires-extent="false"/>
    Class "A" extends java.util.AbstractSet, impl is an instance of
    java.util.Collection.
    All this was working quite well until I made some updates recently
    although the basic implementation is the same. Logically I don't know what
    I might have done to cause the new error message.
    I'm using v2.5.2 BTW.
    Scott
    Stephen Kim wrote:
    The one thing to note is that if you do not make A persistent capable,
    you cannot persist fields -declared- in A or query starting from A.
    Scott A. Leschke wrote:
    Can I acheive the same effect by making A be non-PC and provide a abstract
    protected method that will be used by a to access the collection
    implemented in the sub-classes as you suggest (ie. Collection
    getCollectionImpl())?
    Steve Kim
    [email protected]
    SolarMetric Inc.
    http://www.solarmetric.com

  • Base Class vs Class in the linkage panel

    I have 2 dozen movie clips in the libarary that are all the same structure, but with different content, and I wanted to write a single class that would work for all of them. Popping this in as the base class worked great until I wanted to pass in some arguments to the constructor. Suddenly, it seems I have to write a "shell" class for each asset that contains nothing but super(arg1,arg2) in its constructor (all 24 of them - ugh!). This ends up being really clunky. Is there any way around it?
    Also - in discussing this with a colleague, an issue came up about the exact relationship between the items in the Class and Base Class fields in the linakge panel for a library asset. What exactly is therelationship? Does the class always extend the base class, or is there something else going on?

    undo whatever you did that caused that problem.  you probably assigned a class name that matched one of your base classes.

  • Why cannnot derived class pointer point to a base class object?

    Hi,
    Pleaseeee... explain me why cannot the derived class pointer point to a base class object.
    I know that Base class pointer can point to a derived class object.
    Thanks & Regards,
    Vig....

    Example:
    class Base
    { public: void foo(); } * pBase;
    class Derived : public Base
    { public: void bar(); } * pDerived;
    Now, what would happen if you assign pDerived = new Base() and then call pDerived->bar()?By forbidding such an assignment, compiler prevents you from writing error-prone code.

  • Casting base class object to derived class object

    interface myinterface
         void fun1();
    class Base implements myinterface
         public void fun1()
    class Derived extends Base
    public class File1
         public myinterface fun()
              return (myinterface) new Base();
         public static void main(String args[])
              File1 obj = new File1();
              Derived dobj = (Derived)obj.fun();
    Giving the exception ClassCastException......
    Can't we convert from base class object to derived class.
    Can any one help me please...
    Thnaks in Advance
    Bharath kumar.

    When posting code, please use tags
    The object returned by File1.fun() is of type Base. You cannot cast an object to something it isn't - in this case, Base isn't Dervied. If you added some member variables to Derived, and the compiler allowed your cast from Base to Derived to succeed, where would these member variables come from?
    Also, you don't need the cast to myinterface in File1.fun()
    Also, normal Java coding conventions recommend naming classes and interfaces (in this case, myinterface) with leading capital letters, and camel-case caps throughout (e.g. MyInterface)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Accessing private field of Derived object in Base class

    Hi,
    I have this piece of code I wrote a while ago to test something. The issue is accessing a private field of Base class in Base but of a Derived object.
    Here is the code:
    class Base
         private int x;
         public int getX()
              return x;
         public int getX(Derived d)
              // return d.x;
              return ((Base) d).x;
    }The commented code does not work but casting d to Base does.
    Can someone please explain the reasoning for this.
    Forgot to mention that the compilation error is that x has private access in Base.
    Thank you.
    Edited by: 953012 on Apr 1, 2013 8:42 AM

    >
    As I understand the explanation says that you can access any private member within the code of the class that encloses the private member. So in this case x is the private member and the line of code (return d.x) is in Base which encloses the private member. Does it have to do with the fact that the Derived class does not in fact inherit the private members of Base?
    >
    It has to do with the entire quote from the spec
    >
    A private class member or constructor is accessible only within the body of the top level class (§7.6) that encloses the declaration of the member or constructor. It is not inherited by subclasses
    >
    Your code is
    public int getX(Derived d)
              // return d.x;
              return ((Base) d).x;
         }The 'Derived' class is NOT 'the top level class that encloses the declaration of the member'. It does NOT inherit 'x' which is a private member of 'Base'. As far as the 'Derived' class is concerned 'x' does not exist.
    >
    If outside Base code I have Derived d = new Derived() and I call d.getX() then isn't that like calling d.x in myX()?
    >
    How is that the same? 'Base' owns 'x' and can do whatever it wants with it. 'Derived' has no knowledge of 'x' and CAN NOT access it.

  • Using the Hyperion (Essbase) Objects 6.5  Base Classes

    Hi all,I am using Hyperion (Essbase) Objects 6.5 to report from an Essbase 6.5.3 database. Using the sample report.asp page as a guide, I want to use the "EssProperties" class to change the Essbase options for missing values and using aliases, however there no effect on the results returned when setting these properties.Has anyone out there had any success?

    You need to set the EssProperties class you created into the EssOperations class:set oEssOperations.EssProperties = <your property class instance>Alternatively, you can modify, in place, the instance of EssProperties that EssOperations already has:with oEssOperations.EssProperties .MissingTextString = "Boo!" .UseAliases = trueend withThink of the Essbase Objects Base Classes sort of as a molecule.. The 'basic atom' of the molecule is the EssOperations class (which contains the normal retrieve/zoom/pivot type of operations). Attached to the 'basic atom' are the things that are needed for a successful operation.. First, a connection (the EssConnection object) is 'plugged into' the molecule. Next, properties (an EssProperties object) is plugged in.. Finally, you need a grid to display it on so you plug in a grid object (or, more technically, one of the components that implement the IEssGrid interface).Once you have all of the 'atoms' of the grid plugged in, you have everything you need to do a successful operation.Tim TowApplied OLAP, Inc

  • Can I create the object of an protected inner class of a Base class in to t

    Dear All,
    Can I create the object of an protected inner class of a Base class in to the subclass ?
    e.g.
    public class Base{
         protected class Inner {};
    Public class Sub extends Base{
         Public Inner amethod (){
              Return new Inner(); //here I get an exception as
                                //Inner has protected access
    }Regards,
    Ishan

    @Op. The code that you posted isn't close to compiling. Java is case sensitive. It should be public and not Public, and return instead of Return.
    Kaj

  • How to call a Derived call fucntion with a base class object ?

    Hi all
    i am working on a JNI interface to Java, and in the process of simulating a C++ behaviour in java
    so i need some help form you people, in this regard.
    here is a c++ code, i need a equivalent fucntionality in java , to put it one word, the question is
    how to implement the dynamic_cast functionality in java, as java also has virtual fucntions, i think
    this should be possible, if it is not, what is the alternative
    class Base
    public:
         Base()
         ~Base()
         virtual void F1()
              cout<<"The BASE::F1() is called"<<endl;
         virtual void F2()
              cout<<"The BASE::F2() is called"<<endl;
    class Derived : public Base
    public:
         Derived()
         ~Derived()
         virtual  void F3()
              cout<<"The Derived::F3() is called"<<endl;
         virtual void F4()
              cout<<"The Derived::F4() is called"<<endl;
    Base * GetDerived()
         return new Derived();
    int _tmain(int argc, _TCHAR* argv[])
         Base *ptr = NULL;
                    ptr  = GetDerived();
         Derived *dPtr = dynamic_cast<Derived *>(ptr);
                    dPtr->F3();
    }regards
    pradish

    Just to clarify a point that I consider important--the distinction between references and objects:
    Your subject is: How to call a Derived call fucntion with a base class object ? The answer to that is: You cannot. It is completely impossible in Java. If you have a base class object, the derivced class' methods are not present. On the other hand, if you have a compile-time reference of the parent type, but at runtime it happens to point to an instance of the derived class, then, as pointed out, you can cast the reference. (Note that casting does not apply to objects.)

Maybe you are looking for

  • Connecting 2 local Mac's - .mac authentication question

    I have a Macbook Pro and an iMac, both running 10.5.4. I used to be able to connect between them both in finder, and using Screen Sharing, and it would automatically authenticate using my .mac account. Now it works one way (from the MBP to the iMac.)

  • Mini Bridge does not open after installing 8.0.2 upgrade

    I installed InDesign CS6 upgrade 8.0.2.  Now I cannot open Mini Bridge. If Bridge is not already open,      - selecting File | Browse in Bridge...  or clicking on the Bridge button: Bridge opens - good!      - control-click on the Bridge button: I ge

  • SAP WPC Rendering

    Hi      We are tryng to change the rendering mode of WPC pages to adapt to new multi language support mechanism. We basicly want content to have "placeholders"  that initially are only available in one language(author writes the content) and then a t

  • User Exit for VA01 and VA02 transaction codes

    Hi, I am writing a userexit for PO number checking for VA01 and VA02 transaction codes.The PO number should be unique in the table (vbkd-bstkd).Duplicate PO number entries can be checked with Sold-to Party.If anybody written something like this....pl

  • Hey guys am bharath help me in resolving problem...from past 3 hours am facing this crash(problem

    Problem Event Name: APPCRASH   Application Name: Photoshop.exe   Application Version: 12.0.0.0   Application Timestamp: 4bbc56b6   Fault Module Name: SelectivePalette.8li   Fault Module Version: 2.1.4.20903   Fault Module Timestamp: 50480ff1   Except