what is the difference between doing a class as subclass by inheritance and composition - iphone

what is the difference between doing a class as subclass by inheritance and composition

Composition : the new class has the original class as an instance variable. The interface of the new class starts from the scratch. Only the properties and methods that the new class defines are available to the users of the class. The new class internally uses the old class object.
Subclass : the new class has all the properties and methods it's superclass defines. Any users can use the properties and methods. If the new class does not override them, the superclass implementation is automatically called. The subclass may add new properties or methods.
Usually subclassing is more helpful, but some cases composition can be helpful ( for example when working with class clusters).

http://www.artima.com/designtechniques/compoinh.html
http://www.mapleshirefarm.com/eric/CompositionVsInheritance.html
http://www.apl.jhu.edu/Notes/LMBrown/resource/Composition.pdf
and concisely...
http://www.codeproject.com/Articles/80045/Composition-VS-Inheritance.aspx

Related

What is the difference between class and mixin in dart?

What is the difference between:
class A {}
class B with A{}
and
mixin A{}
class B with A{}
?
In Dart, a class can only extend one other class. But it can implement or mixin as many as you want.
The thing is, when you extend a class, you inherit all its attributes, methods and it's constructors. When you implement a class, if you are adding only methods/attributes that you don't already have, you can simply continue your code. If you are implementing an abstract method, you'll need to actually implement it. Now, mixins are like extended classes, the classes that mix them, are their child as well as with extend and implements, but it has no constructor.
The actual idea for mixins is that you can add functionalities to any class, and they don't have to extend another class. That's why they usually do simple stuff only.

Are these different types of classes the same?

I know that a class can inherit from another class, but there are lots of different names for these.
A child class inherits from a parent class
A subclass inherits from a superclass
A derived class inherits from a base class
Are these all just different names for the same thing? Or am I missing the point?
Generally these three can be the same or different depending on the context,
A super class always suggest that it is the root class so does base class but parent class is a loose term. A parent class class can be a base class and derived class at the same time . It can be the superclass as well. So context matters .
I hope you get the idea .

how can a class or interface can extend more than one class in java

how can a class or interface can extend more than one class in java Please help..
Steps:::javap java.time.chrono.ChronoLocalDateTime in cmd prompt
Compiled from "ChronoLocalDateTime.java"
public interface java.time.chrono.ChronoLocalDateTime<D extends java.time.chrono.ChronoLocalDate> ex
tends java.time.temporal.Temporal, java.time.temporal.TemporalAdjuster,
Excepting Object, which has no superclass, every class has one and only one direct superclass (single inheritance). In the absence of any other explicit superclass, every class is implicitly a subclass of Object.
if you need multiherence you need implements interfaces
look this
https://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html

Is singleton class equal to a class with static method

I created a Class A in which all the methods are class methods (+). Another Class B is a singleton.
I want to know if I can check if Class A [A someoperation] Is like class B in that only one instance of A exists and I do not need to instantiate it.
How can I accomplish this?
When you call a class method, the class is not necessarily instantiated, unless the class method actually creates a class.
Also - class methods do not make a class a Singleton. It just means that the method is called on the class instead of an objet of the class.

Abstract Class and Interface, Object Oriented Programming question

I have a clue about Object Oriented Programming:
I need to have a parent class HandlerException which needs to define the sign of three methods (MethodA, MethodB, MethodC).
Then, I have a child class BusinessHandler which inherits from HandlerException and defines ONLY the MethodA of its parent class.
Then, I have a child class DataHandler which inherits from HandlerException and defines ONLY MethodC of its parent class.
Then, I have a class named CustomerDAO which inherits from DataHandler and consumes the MethodC written on its parent class. (consumes it like: DataHandler.MethodC).
As you can see, its a typical object oriented programming problem; I need to have some static methods (MethodC) to access it directly without any instance of the class. The parent class HandlerException could be abstract? and its 3 methods (A, B and C) could be ???? (that's my question, how is the RIGHT way to write this parent class: abstract with abstract members, or virtual, or maybe an interface?)
I hope you got the idea of my question and that I made myself clear. Thanks in advance.
I forgot: I'm using C#, and to mention: MethodB would be implemented on the next release of the app.
Depends on the language you are using, but it sounds like the HandlerException class would be abstract and all three methods would be virtual.
If the HandlerException class has absolutely no implementation whatsoever (only defines those three methods) then it would probably make sense to make it an interface rather than an abstract class.
Also, where is MethodB implemented? If it isn't implemented by any of those classes, then all the classes would need to be abstract.