I'm trying to define a "Product"-class for my model (.edmx), and I have it in the same folder as the model.
I get: Ambiguity between 'MVCTest.Models.Product.ProductID' and 'MVCTest.Models.Product.ProductID' error
What's needed to do so I can define my classes correctly?
/M
Have you tried using "Partial class"? Only really appropriate if it's an extension of the product class I guess.
If this is not what you were looking for then let us know with more information or even code snippets.
You could always separate out by namespace. Have one class in one namespace. Although having the same class with the same properties is a bit unusual, and suggests that you need to refactor and create some form of inheritance as griegs suggested.
Related
I'm very new to the Grails framework, so please bear with me.
Nonetheless, I am a bit confused on the functionality difference between extending a domain class and embedding objects.
From a database point of view, they both do the same thing. When embedding an object, all the properties of all the classes are stored in one table. Similarily, when extending a class (using table-per-hierarchy), all the properties of all the classes are stored in one table.
I'm sure there is a functionality difference between these two, and so I figured I ask this question.
When do you use either one?
The only technical difference is the ability to have multiple tables through the table per subclass property when extending a class. Otherwise, they are identical in use.
However, that said, by extending another class you are also modeling that within the class structure so you can make use of instanceof and polymorphic features of Java/Groovy.
I have a class written in Objective-C and I want to have another similar one. Except for few details. Is there any smart way of copying class implementation and making another class? I'd like to change few things, but ctrl+c + ctrl+v sounds so unintuitive.
Regards
PS. edit: I have multiple classes to implement, also I'd like to have neat solution for future.
Use class inheritance.
Implement class A with the common functionality
Derive classes B and C from A to add functional differences.
Take a look at Classes Inherit from Other Classes.
If you like to simply add a method without subclassing, see Categories Add Methods to Existing Classes. But be aware what you shouldn't do with categories!
If you like to change values, add appropriate properties to the interface declaration.
Is it possible to override the class file location of a framework class via classmap and autoloader? If yes, then how?
Example: I want to override Zend\Form\Fieldset, so that everywhere in the framework where Zend\Form\Fieldset is referenced, I want it to use my own class file instead of the original.
Motivation: When updating the framework, I want to keep my modifications safe from getting overwritten.
Known alternative: Modify the code in the framework.
Disadvantage: Modification gets lost when updating the framework.
writing the same class (FQCN) at another location is generally a bad idea. This causes two classes which are equally named to live in two separate locations. It's a much better idea to create your own Fielset in your own namespace. Say, Application\Form\Fieldset.
You can extend the ZF2 fieldset by your own. Then reference this new fieldset class and its all much more maintainable.
The downside of this method is you don't automatically use the new fieldset class. You have to reference the Application\Form namespace in every form you use. On the other hand, this makes it much more clear to other users of you code what exactly happens: there are no unexpected consequences using ZF2 code.
The only remark I have to make here is, for what do you need another fieldset? If you think you need that for view helpers, that's not true. You can modify the view helper to render fieldsets without modifying the Fieldset form class itself.
A rule in xText called "Component" will typically generate a class "Component" in the src-gen folder.
I would like to add additional methods to these classes without them being overridden every time I make minor changes to the DSL. What's the proper way to inject my own code into these classes and is there a way to make all classes extend my own root class instead of the default EObject?
Thanks in advance.
You basically have two choices:
You can use a IXtext2EcorePostProcessor to modify the EMF-model which Xtext inferred from your grammar. The actual code generation is done by EMF, so you have to fiddle your code through that bottleneck. The details are described in a blog of Christian Dietrich. This approach is only suitable for small modifications.
You can use the "generation gap pattern" (a.k. "implementation gap pattern") which allows you the write classes which derive from the generated model classes. Here you can add anything you want. The details are described in a blog of Heiko Behrens. This approach is better suited for large scale modifcations by inheritance.
You may of course mix the two approaches...
I'm new in Db4o
As far as I checked, when I do a refactoring of a class name or path (packages),
db4o doesnt recognizes the class anymore and creates a new 'category'.
I want to make an API, so that any class refactoring in my app won't affect the database.
I've created the following function ...
public void saveClassAs(Class objClass, String nameInDB){
configuration.common().objectClass(objClass).rename(nameInDB);
}
and have it called for each of my classes. Since the nameInDB will be constant for each class, no matter where the class is located or its name.
The problem is that Im not sure if will this work and I don't know if this is a good idea in matters of speed ... I didn't find any details on db4o documentation about how the renaming API works. Any help?
If you want to use constant class names (irrespective to the real classes names) my best bet is to use aliases.
Regarding renaming configuration you can find details here.