Is singleton class equal to a class with static method - iphone

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.

Related

How to select a specific class from set of classes which are implementing same interface class?

How to select a specific class from set of classes which are implementing same interface class ?
You don't call a method directly from an interface, you call it on a reference that points to an instance of a class. Whichever class that is determines which method gets called.

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

Swift: Can I create an instance of a subclass with the the class properties referencing an instance of the class?

In Swift, I am trying to create subclasses of a class which will add properties and methods that are specific to certain instances of the class. I would like to initialize an instance of a subclass with an instance of the class, such that the class properties of the subclass instance actually refer to the class instance from which it initialized. My goal is to be able to set a class property in the subclass instance, and have it also set the same property in the class instance from which it was initialized. I have not been able to find a way to create an initializer which accomplishes this, even if I set all the class properties to be the same for the subclass instance and the class instance. The only way I have been able to do this is to add a variable to the subclass and set it to the class instance, but this is cumbersome. Is there a way to do this?
You need to add an appropriate init like this:
class A {
// ...
}
class B:A {
init(clone:A) {
// assign from the other object what needed
}
}

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

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

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.