How to insert a 2D attribute in a class diagram using Modelio tool? - class-diagram

I need to insert a 2D attribute and show it as a parameter of a function in my class diagram using Modelio tool.

In pure UML, you have to create a type intergerArray which will represent interger[0..n] then your parameter will be an array of this integerArray.
If you target a specific code implementation Java, C++ or C# Modelio, as any other tool generating code from Model, has a specific way to specify it.
You can ask it here https://www.modelio.org/forum/index.html

Related

Serialize & Deserialize Unity3D MonoBehaviour script

Background: Classes that inherit from Monobehaviour can't be serialized.
Premise: A way to save the data (variables/fields and their values) of a MonoBehaviour script so it can be serialized, and deserialize it again and use this data to "fill in" a corresponding MonoBehaviour script's variable/field values.
Tried so far:
Having a serializable "wrapper/container" class that has the same fields as the MB script, but does not inherit from MB. Works nicely but every MV script needs it's own wrapper class and it's own wrapping function.
Serializing a List<FieldInfo> and fill it with the MB's fields... Works 30%;
The FieldInfos get added but are of the wrong Type, and
When deserialzing their values can't be accessed because an instance of a class is needed, but only a list is available
I feel like it can't be that hard but my Reflection skills and related are limited but seeing as saving/loading is a rather common feature I hope there is either someone who did it or someone who can point me in the right direction.
There is no easy way to serialize a MonoBehaviour using a BinaryFormatter built in .NET. There are a few options you can consider:
Using a Memento Patter. That is (more or less) what you have tried to achieve using a wrapper. Momento assumes a saving and restoring internal state of objects, so serialization is one of techniques.
Using Unity Serialization, by declaring the methods:
void Serialize(){}
void Deserialize(){}
In your MonoBehaviour script, so within the methods you will choose the properties/fields you want to serialize/deserialize.
There is an interesting framework, source code is on GitHub. It has a custom serialization framework that lets you serialize almost anything (not only monobehaviors). I have never used it, here is the forum page on Unity3d forum, I believe it's worth a look.
The answer to the question is: ScriptableObject. That's what they're for.
Put your variables in a ScriptableObject and Unity will handle the serialisation and give you a custom editor and other nice features. Recommended.

Create new type using reflection

I've read over internet some relevant information that in fact .Net provides possibility to create defined new dynamic type at runtime. First i thought its great news because my current application got hard-coded enum type defined in class. What my thought was i could create that enum usinf reflection and create his enum values from XML. Unfortunetly i tried to find some good tutorial but cannot find something could explain me enough how to do that. Can you give me either some good sample or redirect me to somwhere where i can obtain some knowledge how could i achieve that?

Dynamic argument pasing in corba

I'm new in building corba application. Presently I'm developping a corba application in java. The problem I have is that I should write a method that receive the name of the class, the method and the arguments to pass to the corba server as a string.
Before invoking the remote method, I have to parse the string and obtain all the necessary information (class, method, arguments)
There is no problem here. But now concerning the arguments i do not now in advance the type of the arguments, so I should be able to convert an argument by getting its type and insert it into a Any bject to be sent, is it possible?
If Know in advance the type such as seq.insert_string("bum") it works but I want to do it dynamically.
Use the DynAny interfaces, if your ORB supports them. They can do exactly what you want. From CORBA Explained Simply:
If an application wants to manipulate data embedded inside an any
without being compiled with the relevant stub code then the
application must convert the any into a DynAny. There are sub-types
of DynAny for each IDL construct. For example, there are types called
DynStruct, DynUnion, DynSequence and so on.
The operations on the DynAny interfaces allow a programmer to
recursively drill down into a compound data-structure that is
contained within the DynAny and, in so doing, decompose the compound
type into its individual components that are built-in types.
Operations on the DynAny interface can also be used to recursively
build up a compound data-structure from built-in types.

How to use other clustering methods for clustergram in Matlab's bioinformatics toolbox

EDIT: I figured it out. Just did not understand notation.
Hello,
Hopefully someone out there is familiar with the clustergram in the bioinformatics toolbox. I am interested in the graphical aspects of the function (the dendrogram/heat map), but am currently handicapped as it requires me to use Matlab's cluster() function. I would prefer to use my personal algorithm to cluster, and then allow Matlab to visualize this for me.
I have searched the code, but am woefully ignorant about object oriented programming in general, and Matlab's version in particular. Thus all I know is the function calls the line 'obj = obj.getclusters', but have no idea how to edit it this such that I use my own clustering algorithm instead of Matlab's.
Any help is appreciated!
EDIT: I am specifically working on a new algorithm, hence why I have no need for pdist or linkage. The dendrograms are calculated outside the clustergram function. All I am using to create the dendrogram/heatmap is the clustergram function. My Bioinformatics toolbox is version 3.3
Really, all I am looking for here is what the hell does 'obj = obj.getclusters;' do? I am not a programmer and really am not familiar with OO. To me, that looks like we magically have clusters, as there is no function call. This is at line 304 of clustergram()
First I have later versions of Bioinformatics Toolbox (3.4 and later), and for those versions clustergram.m file does not have the line obj = obj.getclusters;
Remember CLUSTERGRAM in the class (not function as it was it older version). When you run clustergram(data,...) you actually run the constructor method of this class to create clustergram object. This object is obj variable. So when you run obj = obj.getclusters; you actually run getclusters method in clustergram class, which updates the object obj.
To get more details what getclusters method is doing look for a following line in methods block:
function obj = getcluster(obj)
In the latest versions there is method computeClusters defined as
function computeClusters(obj)
This method computes both dendrograms for rows and columns and updates the object. You can directly alter this function, of course, but I wouldn't recommend it. It's much better to develop separate functions for distance metric and linkage and use those functions to construct clustergram object.
If your algorithm does not use distance and linkage, please explain how it's suppose to build dendrograms. Does it create linkage matrix same as output of LINKAGE function? Without such matrix I don't think you can use clustergram even for visualization only. Do you have an example how your clustergram should look like? May be you can use Heatmap class of other simpler functions like IMAGE or IMAGESC.

What is the use of reflection in Java/C# etc [duplicate]

This question already has answers here:
What is reflection and why is it useful?
(23 answers)
Closed 6 years ago.
I was just curious, why should we use reflection in the first place?
// Without reflection
Foo foo = new Foo();
foo.hello();
// With reflection
Class cls = Class.forName("Foo");
Object foo = cls.newInstance();
Method method = cls.getMethod("hello", null);
method.invoke(foo, null);
We can simply create an object and call the class's method, but why do the same using forName, newInstance and getMthod functions?
To make everything dynamic?
Simply put: because sometimes you don't know either the "Foo" or "hello" parts at compile time.
The vast majority of the time you do know this, so it's not worth using reflection. Just occasionally, however, you don't - and at that point, reflection is all you can turn to.
As an example, protocol buffers allows you to generate code which either contains full statically-typed code for reading and writing messages, or it generates just enough so that the rest can be done by reflection: in the reflection case, the load/save code has to get and set properties via reflection - it knows the names of the properties involved due to the message descriptor. This is much (much) slower but results in considerably less code being generated.
Another example would be dependency injection, where the names of the types used for the dependencies are often provided in configuration files: the DI framework then has to use reflection to construct all the components involved, finding constructors and/or properties along the way.
It is used whenever you (=your method/your class) doesn't know at compile time the type should instantiate or the method it should invoke.
Also, many frameworks use reflection to analyze and use your objects. For example:
hibernate/nhibernate (and any object-relational mapper) use reflection to inspect all the properties of your classes so that it is able to update them or use them when executing database operations
you may want to make it configurable which method of a user-defined class is executed by default by your application. The configured value is String, and you can get the target class, get the method that has the configured name, and invoke it, without knowing it at compile time.
parsing annotations is done by reflection
A typical usage is a plug-in mechanism, which supports classes (usually implementations of interfaces) that are unknown at compile time.
You can use reflection for automating any process that could usefully use a list of the object's methods and/or properties. If you've ever spent time writing code that does roughly the same thing on each of an object's fields in turn -- the obvious way of saving and loading data often works like that -- then that's something reflection could do for you automatically.
The most common applications are probably these three:
Serialization (see, e.g., .NET's XmlSerializer)
Generation of widgets for editing objects' properties (e.g., Xcode's Interface Builder, .NET's dialog designer)
Factories that create objects with arbitrary dependencies by examining the classes for constructors and supplying suitable objects on creation (e.g., any dependency injection framework)
Using reflection, you can very easily write configurations that detail methods/fields in text, and the framework using these can read a text description of the field and find the real corresponding field.
e.g. JXPath allows you to navigate objects like this:
//company[#name='Sun']/address
so JXPath will look for a method getCompany() (corresponding to company), a field in that called name etc.
You'll find this in lots of frameworks in Java e.g. JavaBeans, Spring etc.
It's useful for things like serialization and object-relational mapping. You can write a generic function to serialize an object by using reflection to get all of an object's properties. In C++, you'd have to write a separate function for every class.
I have used it in some validation classes before, where I passed a large, complex data structure in the constructor and then ran a zillion (couple hundred really) methods to check the validity of the data. All of my validation methods were private and returned booleans so I made one "validate" method you could call which used reflection to invoke all the private methods in the class than returned booleans.
This made the validate method more concise (didn't need to enumerate each little method) and garuanteed all the methods were being run (e.g. someone writes a new validation rule and forgets to call it in the main method).
After changing to use reflection I didn't notice any meaningful loss in performance, and the code was easier to maintain.
in addition to Jons answer, another usage is to be able to "dip your toe in the water" to test if a given facility is present in the JVM.
Under OS X a java application looks nicer if some Apple-provided classes are called. The easiest way to test if these classes are present, is to test with reflection first
some times you need to create a object of class on fly or from some other place not a java code (e.g jsp). at that time reflection is useful.