Since the array stuff is done, next step is making a class for sequences like C strings - having a set set amount of elements and and limiting character. The point is that every C string is just as big as the memory block you allocated for it. So it's basically just an array with a number of characters used. My problem is that this fact itself doesn't make it necessary to create a class for it. It requires something more... something more special like the ability to combine multiple sequence into one. And that's the point where I'm a bit uncertain. Taking the array class as a base would be kind of the first natural choice - combined with an additional value for it's length (means the number array bytes used til the sequence end value). Only problem is that you'd need to make the array class expandable to make the sequence more useful than just a simply array. So here wo go: that's the basic problem itself. An array has always the same size, no matter what is in it. Especially in C++ you can only really use the new operator to allocte arrays and calling their constructors, so using realloc it no option. Thus it requires allocating a new buffer and transferring existing data to it. In my opinion those functionalities require a new model. There are basically three action: allocate a new memory big enough to fit the old size and the new size (or more generalized: the size of two arrays) and copying the content of array one and then array two. Number one is trivial, done in a single command and and an addition between the two sizes. Step two is something different not really related to the array class itself. Mass-copying content can be effectively seperated and is imho something completely different. So I guess that's the new idea, creating a copier class able to transfer n elements from a to b at position n. Everything using the Array class itself a but more would require such a copy functionality. I think that's the right approach, as you can keep all functionality seperated. So, having a data class itself and a class to modify it, every other more advanced class would benefit from having another class to operate with it's very special properties. I can image having another copier class for the sequence, enabling it to concatenate and alter sequence data. It all depends on what comes to my mind I think. I'm always having trouble to keep my classes not too big and in reality I end up making stuff here and there, just to add the feature I need in the moment. And that'S a problem in general for every programmer thinking a bit beyond per-project featurism (reusing and overhauling code is a key to less work on things you already archieved some time before). I can remember using concept before with a class designed for simplyfying the process of writing software renderers. It had (and still has) a series of classes, some for tracing a specific shape like a polygon or a line, then again others using using these generalized structures to just put pixels shaded pixels whereever the alghorithm defined it. Quite a cool idea! But just too specialized and only usable with an associated class. I want to change that. Keep the base clear and of specific concepts and you're motivated enough to work with this single concept all the time. Maybe that's one of the reason for why people create their own engines or frameworks.

No comments: