Saturday, December 26, 2015

Objective-C vs C/C++

·       The Objective-C class allows a method and a variable with the exact same name. In C++, they must be different.
·       Objective-C does not have a constructor or destructor. Instead it has init and dealloc methods, which must be called explicitly.
·       Objective-C uses + and - to differentiate between class method (known as factory method in Java) and instance methods, C++ uses static to specify a factory method.
·       Multiple inheritance is not allowed in Obj-C, however we can use protocol to some extent.
·       Obj-C has runtime binding leading to dynamic linking.
·       Obj-C has categories.
·       Objective-C has a work-around for method overloading, but none for operator overloading.
·       Objective-C also does not allow stack based objects. Each object must be a pointer to a block of memory.
·       In Objective-C the message overloading is faked by naming the parameters. C++ actually does the same thing but the compiler does the name mangling for us. In Objective-C, we have to mangle the names manually. If you go in deep you will see a complete method names are as : `addA:withB:` which is a selector and `:` is used for parameter.
·       One of C++'s advantages and disadvantages is automatic type coercion.
·       Another feature C++ has that is missing in Objective-C is references. Because pointers can be used wherever a reference is used, there isn't much need for references in general.
·       Templates are another feature that C++ has that Objective-C doesn't. Templates are needed because C++ has strong typing and static binding that prevent generic classes, such as List and Array.