Re: Question
Re: Question
- Subject: Re: Question
- From: email@hidden
- Date: Tue, 4 Dec 2001 05:23:38 -0500
You can't put perfume on a pig.
On Monday, December 3, 2001, at 09:37 PM, Eduardo I. Jiminez wrote:
On Sunday, December 2, 2001, at 11:58 PM, Greg Titus wrote:
You are asking the wrong question, I think - at least, it's the wrong
question if you want a good answer. The way you are asking it you are
almost guaranteed to get an unsatisfactory answer and to come away
with the opinion that Objective-C and Java lacking multiple
inheritance is a _bad_ thing. :-)
Well, I definitively didn't mean that, pardon my English...:). The
thing is that the classes are rather complex, and I already know
protocols won't work for me. From the solutions I've read on the list
(not many, just a lot of flaming), one that could work is composite
objects. I am going to make some comments, and please, keep it to
yourselves if you don't agree (I mean the rest of the people on the
list that are just waiting to flame others based on their PERSONAL
opinions).
I have a class model that I need to implement for a MacOS X application
whose interface will be written in Cocoa. The class model is not
changeable, and like it or not, it has multiple inheritance in it
because it makes a lot of sense. I don't think that 150+ classes is a
flawed system, but it is complex. It is a system with several
components and functionality very well distributed among many simple
objects that map to real entities in the participating processes and
systems.
As an experienced programmer and a growing software engineer, I
recognize the importance of clean, clear, bug-free code. I don't like
patches and I love compiler checks cause they can help you have really
good code. This is a reason I like C++. I like it, I love it. Those
guys who seem to hate it because it is difficult simply don't
understand it. I would recommend you two excellent books on how to make
your life easy (and I mean easy, very very easy): Effective C++ and
More Effective C++ from Scott Meyers (Addisson Wesley). My particular
design does not have (nor it is going to) any diamond shape
inheritance, and operations from classes are entirely different.
Now, back to the point. Sure, I could fix the problem by coding a
composite object (can't use protocols because protocols cannot inherit
from classes, right?) with an union of both superclasses' interfaces,
forwarding calls to a couple of objects that represent each state of
the multiple superclass object, right?. However, this way I would not
gain type equivalence, having to use "id" as parameter type whenever I
need to receive an object like this one. Sure ObjC is great and it will
tell me if I'm doing someting wrong in runtime, but I really prefer
C++'s way (that is, strong typing, where I can specify what I want in)
from a code clarity point of view. Also I have some objects that could
use operators, a great advantage of C++ (also for code clarity in
structure navigation, object comparisons and combining). Another reason
NOT to use ObjC its because it is not portable. I will not be able to
use that code in the future to port the application to another system,
like Solaris, Linux, Windows or whatever. But if my basic framework is
in C++, I can use it anywhere.
You don't really want to model multiple inheritance, per se, you want
to model some specific kinds of relationships between your classes and
you are used to using multiple inheritance in C++ to do so.
Exactly. That is what I want.
I could go into a lot of detail about the different kinds... (One
quick example: one use of MI in C++ is a base class with all virtual
members and then many other classes inheriting from that class as a
way to deal with many different types of otherwise unrelated objects
that all implement the same set of methods. In Java you'd use an
interface instead. In Objective-C you'd use either a formal or
informal protocol - and which was best would depend on other things.
That's the very easiest example because it's an area where I can point
to a specific language feature which is a much better fit for the
design pattern than MI.) But we'd quickly get bogged down in all the
different ways to do things described in very general and nearly
useless terms, and I'd still probably miss some of the patterns that
end up being in your design.
This is not my case. I though of that before, but there is a 4 level
inheritance chain I can't break. I can't put a protocol (or interface)
in the middle. There are ways to achieve multiple inheritance through
delegation, but the papers are not available online. I will search the
ACM to see what i find.
If you are willing to go into some more detail about what your class
design is trying to accomplish we (I) could probably be more helpful.
My basic problem is the fact that I would really hate to loosen type
checking in order to get around the problem. As I said again, I like
the compiler to do work for me. Is it so bad to integrate C++ with
ObjC?. Does it cost more to the application in terms of runtime
structures?. Sure, I cannot change versions of a library as dynamically
as with ObjC, but that is not a priority here. I'd rather have
portability in case I need to port to another OS/platform.
Thanks a lot for the help, and please stop flaming, I'm sure everyone
has more important things to do.
Eduardo Jimenez
_______________________________________________
cocoa-dev mailing list
email@hidden
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
References: | |
| >Re: Question (From: "Eduardo I. Jiménez" <email@hidden>) |