Dynamic type , B-Tree, Archiving and Unarchiving on B-Tree

1- How to create dynamic object and dynamic type?
More detail: For instance if user wants an NSString or each object that foundation Kit and app kit have(NSArray, NSDictionary, …) the system create the object and allocate it.
2- How to create B-Tree and insert each dynamic object to it?
3 - How to add archiving and unarchiving mechanism to B-Tree for each node?
More detail: When each dynamic object that is created at runtime is inserted in B-Tree how to add archiving and unarchiving mechanism.

I am really confused by your question, both in nature and reasoning.

  1. Objective C is by its nature “dynamic”, therefore all(almost all) objects are created dynamically a few exceptions exist like blocks that live in global space and are extern created can be considered to be static objects so can your magic string codex like "static const NSString *const BEGINCODEX = @“aMagicString”.

An example of a “dynamic” object in C++:

MyClass *myPtrToMyObj = new MyClass;

The key word new is an abstraction of the “new” operator that is now defined in the library of C++11. The abstraction is a result of revisions to the language that has lead to the both fantastic and painful C++11 standard; fantastic as a systems and device driver developer painful as grad student being forced to teach C++ to the general population. As an aside I would be far better off teaching them ruby or python then anything resembling an imperative language however teaching lets me develop in my free time and is oddly more lucrative then being a research assistant. My students have all decided as a mass that “new” is the keyword of amazing awesome “borktastic”(Mark!) dynamic. I bring this up because this sounds like a similar situation(I think I am about to do your homework for you which is cool since it was a month ago). “new” is just an operator in C++ that people like to think of as the dynamic word, oddly enough it is just a reserver word for the allocation of space and initialization per the constructor(hint, hint).

I am going to answer “create the object and allocate it” part of your question out of order and I hope you will understand why after reading this.

NSObject *anObject = [[NSObject alloc] init];

ok since we are all pro at imperative languages we are going to with order of operations being give as such without justification of lhOp vs rhOp of assignment etc
a. [NSObject alloc] This "alloc"ates the space, it is done at runtime which means it is dynamic this space is in the heap and not on the program stack . I will call its resulte SpaceForAnObject
b. [SpaceForAObject init] This creates the object by initializing its iVars, I am going to leave it there and hope that covers it for now. I will call this (id)anInitializedObject.
c. NSObject *anObject = (id)anInitializedObject; This assignment of the (id)VAR is without getting to heavy into stuff tellng anObject to point at the place in the heap where VAR was just dynamically created so we have a way to get to it.

So to recap allocate space initialize object “alloc] init];” works.

  1. A B-Tree… now that is without a doubt homework. I would strongly recomend looking up a book on “INTRO to data structures” a binary tree is a simple data structure that you should study and not have the interweb forum folk tell you how to design and implement. However I will give a few pointers of the steps I took when last I implemented a generic container. These are the same pointers that are given in a class called “INTRO to data structures” :

    1. Object Oriented programming is Object Oriented break down your classes to be small and simple use aggregation where ever you can versus composition
      nothing makes me draw more “sad faces” on a paper I am grading then incomprehensible subclassing. A human being is not a subclass of a heart and it does not make any sense to subclass them as such even if you can get the ivars to work out dont do it! A human being has a heart.
    2. Break down your B- Tree into a few parts like “Tree” and “Nodes” and have nodes do things they can like hmmm traversals HINT because smaller classes are easier to debug.
    3. Google it lots of places have containers implemented for copy and paste… just change it enough so MOSS doesnt kill you.
  2. Make your Node classes which you wisely made a different class and not just a struct in your tree implementation NSCoding compliant, do the same theing for your tree and then type check when you go to archive to make sure the objects being stored in the nodes respond to the the NSCoding protocol handle errors as your TA/Prof/Angry Grad student wants you too

For your more detail part… I do not really think you should be doing this period because the only requirement to “archive/unarchive” in Cocoa is NSCoding, you do not understand this or you would not be asking this so building it into a generic container is going to be a rough learning experience. My guess is you are a student… most likely in Data Structs 1 if you are and you are mostly familiar with Java, again just a guess, a C fam language has a steep learning curve for trying to jump in at the DS level, a C fam language that usses a runtime enviornment is worst. Goodluck!

It was a very memorable read it. It is all very well until I wanted to study it further.