Solved

Creating an abstract class with a Protocol for child classes

Posted on 2012-04-13
2
637 Views
Last Modified: 2016-02-10
I am new to Objective-C but I think I would like to create:

1) An Abstract class which performs certain functions needed by child classes, but should not be instantiated directly.
2) A Protocol that forces child object to conform to a standard interface
3) Child classes which inherit from this Abstract class and conform to the Protocol.

I understand that Objective-C will not let me enforce that a class is Abstract, but that's okay. I will name it with "Abstract" in the object name. I would like the child classes to be the highest level which conforms to the Protocol, otherwise I would need to make the Abstract class do so, then have empty methods to be overridden, and I am not even sure how to do this.

So please explain a different way to accomplish this or provide me the syntax to make this compile.

Thanks.

P.S. Is the "C" Topic Area the correct place to post questions for Objective-C?
0
Comment
Question by:newbieweb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 33

Accepted Solution

by:
pgnatyuk earned 500 total points
ID: 37845894
Objective-C is not C++ or Java.  I'd say, it's better don't think in terms of the abstract class.

You can take a look here:
Abstract Classes with Objective-C

You'll find this code:
- (id)init
{
     [self doesNotRecognizeSelector:_cmd];
     [self release];
     return nil;
}

Open in new window


Or just use NSException and @throw.
Throwing Exceptions
@throw [NSException exceptionWithName:NSInternalInconsistencyException
                               reason:[NSString stringWithFormat:@"Override %@", NSStringFromSelector(_cmd)]
                             userInfo:nil]

Open in new window


I think the correct way is to  use the Formal Protocol.
The Basics of Protocols and Delegates

Protocols
0
 

Author Closing Comment

by:newbieweb
ID: 37848387
Thanks.
0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question