anything like a java object in abap programming? - abap

is there any type of Object in abap, so that I can save any kind of data in it?
the reason is the following:
I'm writing some code and I dont know what kind of data I will get back. If I would work with java I would save it in a Object.
Is there something equal in ABAP?

If you are looking for data types, there is a generic type named DATA. For objects (instances), a similar type named OBJECT exists. The generic type ANY will contain either one of these, but it's rather pointless to use it for both objects and values at the same time, because you'll end up handling data with references which can be really error prone (and is not something you should attempt to do if you don't know about generic types in the first place).

Related

how efficient is Object type in vb.net?

I have dynamic item attributes in a dictionary that could hold either a single or a string or 2 other custom classes.
Right now i store the value in a class that has uninitialized variables for all of these and another variable to say which type to get upon request. I don't like it because it's rather clunky and seems to waste memory (since most of the time the value stored is a single).
I figured i could hold any of these in a single object variable type but i don't know what kind of penalties to expect from this, if any. Should i continue with managing the types myself or let vb figure it out?
The main thing you should worry about with the Object type in VB.NET is late-binding. If you call a method on an Object variable (except for those methods that are part of the Object type, such as ToString), the vb runtime has to use reflection to find and call the correct methods on the exact type when they're executed. If you use a specific type for your variable, that lookup will only occur once, when your code is JIT-compiled. I would say that the overhead of late-binding is significant enough that you should avoid it when possible.
However, that doesn't apply to checking the object's type and assigning to a variable with a more specific type. So if you figure out what type of object you have and assign it to the right type of variable before calling methods on it, you should be ok. There is a little bit of overhead to doing that, but it's probably no worse than what you're already doing.
Another reason to avoid late-binding is that it prevents the compiler from doing type checking.

Some questions on enum and streamwriters vb

Some questions i had regarding vb.net functions:
How do you differentiate between an enumeration and a record? As far as i'm aware an enumerated type is simply one constant with multiple identifiers and that a structure contains different data types?
When declared, does a variable of a structure type need to use all its fields or can some be omitted?
Am i correct in saying sets don't exist in vb.net and the closest thing is an arraylist?
Is there much of a difference in streamreaders/writers and binaryreaders/writers when referring to reading and writing to text/binary files in terms of being called and used? (Aka is the only difference the data being read? [2-3 line examples would help]
I'm a bit confused about transformation variables; I know that they gain their value from the fixed calculation of another variable, but i can't seem to gain an understanding of it.
How do you differentiate between an enumeration and a record?
In what context? Basically an Enum is a list of constants and can be used pretty much anywhere. Records mainly have to do with Databases and Datasets, which means a record could be made up of any data types
As far as i'm aware an enumerated type is simply one constant with multiple
identifiers and that a structure contains different data types?
A structure is basically a way of organizing a certain set of variables.
When declared, does a variable of a structure type need to use all its
fields or can some be omitted?
Every field is part of the structure when it is declared.
Am i correct in saying sets don't exist in vb.net and the closest
thing is an arraylist?
Not sure what you mean by set. .net contains classes for several different types of collections, of which arraylist is just one.
Is there much of a difference in streamreaders/writers and
binaryreaders/writers when referring to reading and writing to
text/binary files in terms of being called and used?
Basically the main difference is that because binary doesn't normally include line breaks, that method uses buffers, where as text readers use strings and recognize line breaks.
I'm a bit confused about transformation variables; I know that they
gain their value from the fixed calculation of another variable, but i
can't seem to gain an understanding of it.
Not really sure what you're getting at here. I suspect that that has to do with higher math functions and not really .net specific.

Method name suggestion for clone-like method

Objects in my open-source toolkit are all based on the class AbstractObject. I want to add a function into AbstractObject which will create and return object of the exact same class.
This is different from cloning, because the property values are not copied. I thought about calling it duplicate but it is confusing when working with ActiveRecord classes (as duplicate would be used to duplicate record, not object).
form2 = form1->createObjectWithSameClass()
Please suggest a single-word (preferably) name for this. I appreciate your time!
Based on the information here, this sounds like you want another plain object of the same type as a variable in scope, and that type is the only context needed when creating the object.
In that case, this sounds like a valid case for a Factory instead of a method hanging off of an instance. You could do, perhaps:
myFactory.create(form1)
or
myFactory.create(form1.getClass())
EDIT: this is not a direct answer to your question, but because you are concerned with naming, and therefore I assume with clarity of code, one of the big benefits of a pattern is clarity (everyone knows what a Factory is, so they won't be confused by whatever name you end up choosing).

Reading a pointer from XML without being sure the relevant Obj-C instance exists

I have a "parent" Obj-C object containing (in a collection) a bunch of objects whose instance variables point to one another, possibly circularly (fear not, no retaining going on between these "siblings"). I write the parent object to XML, which of course involves (among other things) writing out its "children", in no particular order, and due to the possible circularity, I replace these references between the children with unique IDs that each child has.
The problem is reading this XML back in... as I create one "child", I come across an ID, but there's no guarantee the object it refers to has been created yet. Since the references are possibly circular, there isn't even an order in which to read them that solves this problem.
What do I do? My current solution is to replace (in the actual instance variables) the references with strings containing the unique IDs. This is nasty, though, because to use these instance variables, instead of something like [oneObject aSibling] I now have to do something like [theParent childWithID:[oneObject aSiblingID]]. I suppose I could create an aSibling method to simplify things, but it feels like there's a cleaner way than all this. Is there?
This sounds an awful lot like you are re-inventing NSCoding as it handles circular references, etc... Now, there might be a good reason to re-invent that wheel. Only you can answer that question.
In any case, sounds like you want a two pass unarchival process.
Pass 1: Grab all the objects out of the backing store and reconstitute. As each object comes out, shove it in a dictionary or map with the UID as the key. Whenever an object contains a UID, register the object as needing to be fixed up; add it to a set or array that you keep around during unarchival.
Pass 2: Walk the set or array of objects that need to be fixed up and fix 'em up, replacing the UIDs with objects from the map you built in pass #1.
I hit a bit of parse error on that last paragraph. Assuming your classes are sensibly declared, they ought to be able to repair themselves on the fly.
(All things considered, this is exactly the kind of data structure that is much easier to implement in a GC'd environment. If you are targeting Mac OS X, not the iPhone, turning on GC is going to make your life easier, most likely)
Java's serialization process does much the same thing. Every object it writes out, it puts in a 'previously seen objects' table. When it comes to writing out a subsequent reference, if it's seen the object before, then it writes out a code which indicates that it's a previously seen object from the list. When the reverse occurs, whenever it sees such a reference, it replaces it on the fly with the instance before.
That approach means that you don't have to use this map for all instances, but rather the substitution happens only for objects you've seen a second time. However, you still need to be able to uniquely reference the first instance you've got written, whether by some pointer to a part in the data structure or not is dependent on what you're writing.

Parsing files to set data of an object - a design question

I recently had to write some code which parsed a file to set data in an object. As there were several objects and corresponding files involved here, I decided to separate the parsing code out.
So I then had one class for parsing the files, CommandFileParser, and two classes per file/object type: one for the actual object itself and one for the possible commands that may be used to set the data in the object. e.g. VectorDrawing and VectorDrawingCommands. The latter's methods would be called by CommandFileParser using reflection as it found them in the input file, and applied data to the former.
But to me this seems like a really messy way of doing it. I ended up repeating loads of boilerplate code doing stuff like dataobject.value = value in all the of -Commands classes. And I don't like having an auxillary class per main data class just to set the data.
Can anyone suggest any ideas for cleaner and more appropriately OO ways of doing this?
"I ended up repeating loads of boilerplate code doing stuff like dataobject.value = value."
The assignment statement isn't really "boilerplate". It's the most important statement you have; the fact that there are many means you're doing lots of important things.
However, other "boilerplate" could be anything. Could you provide examples of the specific boilerplate you object to?
If all of your commands just involve direct assignments, perhaps you don't need the command objects. Can you directly do reflection on the objects themselves and get rid of the command objects entirely?
Another possibility is that you have two classes of commands: One is directly implemented by the object, e.g., simple property setting, and the other that is implemented by external command objects, e.g., for commands that need to do calculations or set multiple properties. You do the same reflection as before, but just check two objects.
BTW, I like the idea of using reflection to look for commands. It makes it incredibly easy to add new commands.
I don't know about VB.Net, but in all OO language with which I'm familiar, the normal approach is for a mutable object to contain the methods that set its own attributes' values, rather than putting that work into a second class.
Is there some reason why you wouldn't put the methods in your current VectorDrawingCommands class directly in VectorDrawing instead, and eliminate VectorDrawingCommands completely?
Maybe you want each Class to inherit the CommandFileParser instead of separating it out.
Why couldn't you just use reflection to set the values of the fields or properties directly and remove the entire concept of the -Commands classes?