why is that I can't create an instance_free feature in a deferred class? - eiffel

I'd like to create a class with both an instance_free (ensure class) feature and a deferred one.
why is that I can't call an instance_free feature in a deferred class but only on a descendant?
Don't understand the logic of that... is there for compiling reasons? or any sense I don't see? Where am I wrong with my logic?

This is an implementation constraint of the current version of EiffelStudio (19.07). It is going to be removed in the future.

Related

AutoFixture AutoDataAttribute Customization Beyond Derived Attribute

I am using the AutoDataAttribute class within AutoFixture.Xunit2 in a lot of projects. The recommended approach to add your own customizations seems to be a derived attribute like the following (note I am using FakeItEasy):
public class AutoFakeItEasyDataAttribute : AutoDataAttribute
{
public AutoFakeItEasyDataAttribute()
: base(() => new Fixture().Customize(new DomainCustomization()))
{
}
}
In an effort to reduce code copying/pasting, I wanted to abstract this derived attribute to a package we could consume in our projects. However, despite attempts utilizing dependency injection with this library and running into CLR issues with the DataAttribute not able to take anything beyond basic "primitives", I have ran into the proverbial "brick-wall". Obviously constructor injection doesn't seem to work here nor property injection to my knowledge (although unlikely that matters as the property isn't allocated until after the constructor call anyway).
The bottom line, I am looking for a way to include this derived attribute into a package but in a way where the domains can be customized for each individual project's needs?
I don't think what you're trying to achieve is possible due to how attributes work in C#. As you mentioned yourself you cannot pass into the attributes but a small set of primitive values, and in xUnit 2 data attributes don't have access to the test class instance, so you can not inject instances via reflection.
You could theoretically inject the IFixture instance into the test class using the library you mentioned (which I think is a horrible practice, that promotes sloppier tests), but then you'd have to give up the decorator notation of AutoFixture and use the declarative notation, to create your test data.

Sencha Touch 2.3.x - is there a universal method to call a function from another class?

I'm stuck with a very simple issue - calling functions between classes. Say I have a function (renderMap) in one of my already defined class: App.ux.MyClass (I also added this class to 'requires' in app.js). How to call the 'renderMap' function from other classes?
I tried App.ux.MyClass.renderMap() but I got 'undefined is not a function'.
I would solve the problem by creating a mixin that would contain all functions shared by many classes. See the mixins docs for details.
Then you would just call
this.renderMap()
in any class that uses that mixin.
I think it's problem in application architecture.
You can to use DI (it will be best choice), but, if you cannot, try to create Singleton or ServiceLocator patterns (yes, I know they are anti-patterns).
In ExtJS 4.x and Sencha Touch 2.x Singleton can be created via statics definition in class. Read more: http://docs-origin.sencha.com/touch/2.3.2/#!/api/Ext.Class-cfg-statics
Then, you just can to call method like App.ux.MyClass.methodName().

Best approach to extend a Camel Route

We have lots of routes which do common stuff. I would like to move that stuff into a Base Route and add/overwrite functionality (e.g. adding system dependent headers, doing system dependent enrichments, etc) in the extension.
What is a good approach for that? Would it make sense to use the AdviceWithRouteBuilder since I saw only examples where it is used in unit tests?
Are there other ideas?
Thanks
Yusuf
You can do "sub routes". I have found them very useful for doing common tasks.
Create something like this inside a "CommonRoutes" route builder:
// Example
from("direct:extractCommonMetadata")
.setHeader("orderid").xpath("/data/orderid")
.setHeader("customer").xpath("/data/customer")
from("direct:enrichWithCommonStuff")
.enrich("foo:baz")
Then you can simply do this in your various routes:
from("foo:bar")
.inOut("direct:extractCommonMetadata")
.inOut("direct:enrichWithCommonStuff
.foo("bar")
from("bar:foo")
.inOut("direct:extractCommonMetadata")
.to("the little house on the hill");
The overhead of using the direct protocol is very low and a good way to break out common functionality.
If you use Java then its just java, and you can create a base RouteBuilder class, and do some shared stuff in the configure method, and call super.configure() from extended classes.

Does dependency exist if A is only used in a method of B?

I have a class Idea and class Generator
In Generator's run() method, a list of Idea will be constructed and returned as return value of run()
I only know that if Generator has a member which is a list of Idea, their dependency relationship will exist certainly. But how about the situation I mentioned above?
When looking at dependencies, ask yourself what would happen if you didn't have that particular class. If it wouldn't run/compile, then there is a dependency. So yes, Generator has a dependency on Idea.
Dependencies are displayed at classifier level in the class diagram. I mean that if two methods call each other then there is a dependency. You have different kinds of dependencies which are displayed with a dependency link and a stereotype such as << call >> etc..
Below is an example:
(source: forum-omondo.com)
The situation you are describing is a Usage dependency following the create stereotype. It is indeed a classic example of dependency, as noted here:
Dependency relationships in UML

Is using the RequestHandlerComponent in a model possible?

I'm new to PHP and decided to use the cakePHP framework to help me get started.
I can't figure out one thing though, I want to call methods on the RequestHandlerComponent class to update a users last used IP address and other information, I figured the best place to put this would be in the beforeSave() method on the User model.
I can't figure out how to call the getClientIP method though.
The normal code that would otherwise go in the controller doesn't work. Is there another way to call this class if you're in the model and not the controller?
Class Level:
var $components = array('RequestHandler');
And in the function:
$this->data['User']['lastActiveIP'] = $this->RequestHandler->getClientIP();
Gives:
Undefined property: User::$RequestHandler
Call to a member function getClientIP() on a non-object
Components, by design, aren't available to models (without bypassing MVC convention - which you can do, of course). If you chose to force it to be available, look into ClassRegistry::init(). A better solution, I think, would be to employ the RequestHandler component in your controller (where it's meant to be used), set the lastActiveIp value in the controller (exactly as you've shown in your own example code) and pass the entire data array along to the model.
Now your component is being used where it should be and the model gets to remain ignorant about where it gets its data. At the risk of oversimplification, all the model should know is what to do with the data once it arrives; let the controller worry about collecting and packaging the data.
In addition to Rob's answer, maybe it's enough to put a bit of code together yourself that uses the general env('REMOTE_ADDR') or similar variables. Look at the RequestHandler code, it's not doing anything terrifically complicated.
You may even be able to call the component statically, which is slightly better than instantiating it in the model (still in violation of MVC though). Untested, but should work:
App::import('Component', 'RequestHandler');
RequestHandlerComponent::getClientIp();

Resources