I am working on an extension in Jena, where I have to add new Update element similar to UpdateModify but the logic is different and I do not want to extend UpdateModify. The UpdateVisitor interface does not have a visit method for the new element. What would be a suitable way to proceed in this case?
Create an interface which extends UpdateVisitor, add my new element's visitor method, in that case I have to rewrite all the other update instances which implements this newly extended interface. Is this a good way to implement this?
Related
Do you see any way to know when ANY model’s property has been modified through a binding?
I would need something generic because it would be applied to all the forms of the application. This means I cannot just have a 'property’Changed() observable callback for every properties of the models. I’m thinking along the ways of overriding the properties setters created by the binding engine so they can call a single defined callback but I feel like there could be a better way.
I created a aurelia-plugin for this kind of scenario (and more).
Its not exactly what your asking for, but can help you a lot.
because the plugin will create a single property called isDirty that you can observe and fire your code accordingly.
https://github.com/avrahamcool/aleph1-aurelia-utilities
look at the Dirty Tracking a model: section
your model class need to extends the baseClass provided by the plugin.
now you can decorate any properties of your model with the
#dirtyTrack() decorator.
for babel users: the assignment in the declaration will set the
default value for the property. for TS users: you should call the
decorator with a parameter #dirtyTrack(7) someInt: number;
this will set up a isDirty variable in your model. this property will
be automatically updated to with every change to your tracked
properties.
at any point, you can call saveChanges() on your model, to commit the
current changes. or discardChanges() to revert back to the last saved
point. you can call serialize() to get a pojo object from your model,
or deserialize(pojo) to populate your model from a pojo object.
Ok, I ended up just using the binding engine to watch all properties changes. This allowed me to implement my isDirty checks without modifying the existing models...
So the final code looks like this:
Object.getOwnPropertyNames(obj).forEach(p => {
this.subscriptions.push(this.binding.propertyObserver(obj, p)
.subscribe(() => this.updateDirty()));
});
my updateDirty() method is called after every property change and no change was necessary to the model.
If anyone can come up with a better solution, I'm still interested but this fits my needs for the time being.
I'am using a third-party framework that provides a class whose instances only have properties. In my app, I'd like to add an extra property to this instances. What the appropriate way to do this would it be for this scenario?
a) Extending the framework's class in my app
b) Creating a subclass of the framework's class and define the new property I need
Thanks in advance
It's
b)
because adding (stored) properties in a class extension is not supported.
There are two important rules for using extensions:
Extensions can add new functionality to a type, but they cannot override existing functionality
Extensions can add new computed properties, but they cannot add stored properties, or add property observers to existing properties
It depends on what is the behaviour you are expecting to achieve.
Extending: You can only add new methods and computed vars, but you will achieve seamless effort in your code. the new functionality is available anywhere without adding new classes in your code
Subclassing: You can add new vars and override function but there is a bigger footprint in your code. You will need to use that specific subclass throughout your project.
I guess it is more of a design question.
My suggestion: if the entire project needs this new behaviour use extensions, otherwise subclass.
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.
Upon reading this question I wondered if it is really needed to extend CustomEvent if you want to have custom DOM events in your application. Would it be possible to just extend Event or does CustomEvent serve a special purpose for technical reasons?
An example I was thinking of: a login component with 2 properties "username" and "password". I can imagine a LoginEvent with those two properties. I could either:
have the two properties as properties of the event class, in which case I don't need/use the detail of CustomEvent and hence may not need to extend CustomEvent.
pass them in as an array to the detail property of CustomEvent.
create a LoginParams object with the two properties and pass this in to the detail property of CustomEvent.
CustomEvent.detail is meant exactly for this, though the types must be passable to JS so there are some restrictions.
It'd be nice if you could extend CustomEvent, but that had similar issues as extending Element.
I just want to know if there's a way to access the properties from a utility class used by an Action class. To access the properties from an Action class we extend the ActionSupport and use the getText("property.key.name") method.
So, my question is -should every other class extend the ActionSupport to access properties, even though its not an Action class? or is there any other way?
Thanks
I wouldn't extend ActionSupport unless you're actually defining an action.
The S2/XW2 ActionSupport class uses com.opensymphony.xwork2.DefaultTextProvider; you might be able to use it in your own classes. I'm a little wary of this since I'm not convinced non-action classes should be accessing the web-app's resources, but I haven't given it much thought, so it could be valid. I also haven't tried to do it.
ActionSuport is kind of helper class being developed by S2 developers to supplement the Development as it provides many features OOTB.
getText() is one of the use-case where S2 provides a way to read the property files.This method is specific to S2 as it know how to transverse the hierarchy to read the property files and in what order.
There are many ways to read the property files in a application and few of them are
ResourceBundle
if you are using Spring, it has a very handy mechanism to read property files
- how-to-read-properties-file-in-spring
Apache Common also provides a way to read the file
Apache-Common
In short to read properties file there are many ways, S2 getText() is a way developed by the S2 to read the property file with respect to your actions.
//I wanna make you understand how struts doing it.
public class ActionSupport implements Action, Validateable, ValidationAware, TextProvider, LocaleProvider, Serializable {
//Action support implementation.
//Here TextProvider takes care about resource bundle thing.
}