Which of the following are true for singleton classes? - singleton

dear all sorry for asking basic question.. i still did not understand about singleton.
i still can not figure the answer.
Which of the following are true for singleton classes?
a. Cannot be derived by other classes.
b. Cannot be referred to in a variable.
c. Not more than one instance may exist ever within a runtime.
d. They are thread safes

The answer is C, that's why singleton is "single-ton". It should be very easy if you have put in some effort to google it.

Related

Will bill Pugh singleton solution would work on objective c ?

I know bill Pugh is thread safe and recommend way to use.
I searched a lot about it in the internet but couldn't find an answer.
is bill Pugh solution will work on objective c as well ?
I know it will work on java, but do some of you have experience in objective c?
Had to look up The "Bill Pugh singleton".
Sure, it could be used in Objective-C, but why bother? There is already a perfectly good singleton pattern in wide use in ObjC (that largely implements the same pattern anyway; the singleton is only created on first access).

Objective-C class with multiple class variables

I am writing a class that has many class variables. So I am declaring the variables as static in my .m file and before #implementation statement, with setters and getters for them as class methods. Is it a good idea to do this for lets say more than 10 class variables? Or is there a better alternative to do this?
Without more information that's a tough call. Technically working - yes.
I know many people don't like singletons, but maybe this is one of the good use cases for it?
Maybe you find that configuring one of those classes, or now objects, really doesn't have to be a singleton at all?
Just because there is only one instance of a given class doesn't mean in cannot be a "normal" class.
Class variables often mystify your state all over your code base and make debugging and code reuse a pain. Let alone multi threading.
Edit: Given your usecase as described in a comment to another answer, I'd go with a singleton, i.e. a 'SoundPlayer' class. '[[SoundPlayer sharedInstance] playCoolSound];' is easy, and you get proper instance variables there, too. And you can always exchange it for another class if needed (think test cases etc.).
Well, I can guarantee that the computer will have no problem with it. They're pretty good with large numbers.
Without knowing more about your situation, it's hard to say. It does sound, though, like you're potentially going about it in a way that isn't optimal. It's good that you followed your intuition and are asking about it. Perhaps you should modify your question (or ask a new one and link it here) to talk about what you really want to accomplish, and then we can help.

Using functionality of one class in another

I'm trying to use ILGeoNames classes in my project. But I have problem with understanding in which way I can use this classes for my purpose. There is "simple project" in this framework. From it I want only one thing: country time zone (I already have county name). Because there are many method, variables and others staffs I can't understand what exactly I need to use. Please, help me solve this question.
If its a bunch of classes and you want to make use of a certain class's methods or properties, then you have to #import name_of_class_you_want_to_utilize; at the start of your file and then make your calls. Class methods can be called directly, whereas instance methods require you to create an instance of the class to access them.

Objective C Terminology Help

So I know a bit of C, trying to jump into ObjC for Max apps. Trying to figure out the terms and just needed a guru to humor me.
So an object could be thought of as a house that holds operations and data together.
But there may be many different objects of the same kind, called an instance. This could be thought of as a trailer park (manufactured home community) with a bunch of object homes. Not sure how to give an example of a type however.
Following same example, the methods would be the way the data in the house is manipulated?
Trying to figure these definitions out in a very simple example for my brain :)
It sounds more like you need some education on Object Oriented Programming in general rather than Objective-C specifically. Do some googling for general OOP references. Here's some basics referring to your specific question:
Object: A general term for a combination of data and related operations
Class: A specific definition of an object, i.e. NSController
Instance: A specific object created from a Class definition
So, I could have an object Controller1, that is an instance of the NSController class. This could be referred to as an "NSController object" or an instance of "NSController".
Stop using these analogies, just start playing around with tutorials and the code, you will get the hang of what everything does in no time.
In my words I would call methods a collective of instructions that you can call on with the given method name.
But really, just start writing code, the rest will come :) (no copy pasting!!)
What you're asking has little to do with Objective-C specifically, and everything to do with Object-Oriented Programming. Read up on that before diving into the new language!
I know this topic is quite old, but I thought I'd try and help out in case anyone is coming here looking for answers.
Object
Blueprint for a house. It has the plans for building a house, and it will even supply the contractors to build the house for you, but it is not the house.
Instance
This is a house. It also keeps track of all of the characteristics of the house, and as a result it can be introspective. IE: You can ask the house how many rooms it has, what its dimensions are &etc.
Method
Most every object will define methods. Methods do stuff. Following the house analogy, a method would be the mechanism that would grab the dimensions for you and print them out, or it could be something that would modify the state of the house. IE: call a plumber to fix a leaky pipe on the house.

Objective-C newbie: Does anyone know of diagrams that explain class, objects and methods?

As you may have guessed from the question - I am right at the beginning of the Obj-C journey.
I'm hoping that someone out there knows of some diagrams that depict the relationship between classes, objects and methods - and that they're willing to share.
The problem I'm having is that just looking at code in a textbook doesn't completely explain it - for me at least.
Thanks for reading!
Regards,
Spencer.
No diagrams, but this is the tutorial I wish I'd read before I started:
http://www.cocoadevcentral.com/d/learn_objectivec/
Simple English, all the basic concepts.
Classes are just like classes in any language. They are descriptions.
Objects are like nouns. They are an instance of a class. That is, if you had a description of a generic book (the class) and you made a thesaurus based on that description, the thesaurus would be the object.
Methods are more or less functions. If the objects are nouns, then the messages are verbs.
[ScienceBook getTableOfContents]; //this would like return a table of contents.
Here, the object ScienceBook is being sent a getTableOfContents message (method). So now, the science book would theoretically find, format and return the table of contents to whom ever sent the message.
To some extent, diagrams may not be that helpful to answer the questions you present.
It may help to think of things like this:
A "class" provides the prototype or definition for some thing. For example, a "Person" or a "Car". A common synonym for "class" is "type".
An "object" is a concrete example or instance of a class. For example, you are an instance of "Person", and your car is an instance of "Car".
A "method" is a behavior, action or property of a class. However, a method is normally only meaningful in the context of an object. "Person" -> "Eat" is not meaningful, but "you" -> "Eat" is.
These are fundamental Object-Oriented concepts that are not specific to Objective-C. If you are interested in a general overview that is language-agnostic, I recommend "Object Thinking" by David West. Even though it's from Microsoft Press, it covers the concepts rather than any specific language.
I come from a fairly strong C++ background, but I can definitely remember when I started, I had a hard time grasping at the concept until I found a way to associate it with physical objects.
The word class and object you can use almost interchangeably. Think of an object as a container, like a bucket. The word bucket would be your "class". It is the name you give to the type of object you have.
A bucket has a certain purpose...to carry something. It might be water...or perhaps sand. So perhaps you want to fill the bucket. This would be something you do to the bucket, so in objective-c, this would be your method. You might write something like:
- (void) fillWith:(elementType)something;
So in this case, "something" might be something that represents and object you wish to fill your bucket with.
Your class might look like the following:
typedef enum items {
CRAYONS,
MARKERS,
SAND,
WATER } elementType;
#class Bucket {
elementType item;
}
- (void) fillWith:(elementType)something;
#end
Here's one link to some objective-c samples. Also try the apple development center.
If you're after information on Object Orientated Programming (ie the meaning of classes, objects, methods etc) then I'd advise against Objective-C. Objective-C on the Mac relies heavily on the Cocoa framework. The Cocoa framework is vast and performs a lot of 'magic' which will make it harder to understand the fundamentals of OOP.
An easier place to start would be a language used for web development. It's easier to get to the nuts and bolts of OOP with these languages.