Learn strangeioc–binding together with Keyle

Source: Internet
Author: User

Strange:the IoC Framework for Unity Binding

The core of STRANGEIOC is a very simple binding package that creates an indirect binding that mitigates the code's reliance on other parts of the program.

The core of Strange is a very simple package for binding. This means, essentially, which we can bind (connect) One or more of the anything to one or more of the anything else. Tie an interface to a class that implements that interface. Or tie an event to a handler. Or tie, classes such, the one comes into being, and the other one is automatically created. Why would we does this? So glad asked! It turns out that much of the when programming comes down to the binding. If you've ever dispatched an event (or a SendMessage in Unity), if you've ever indicated that one class uses another class , if you've ever written so much as a "if...else" statement, you ' ve engaged in some form of binding. That's, you ' ve tied something to something else.

But binding things directly was problematic, because it results in code that's hard to change (rigid) and easy to break (brittle). For example, I ' m sure you ' ve programmed something in which you ' ve expressed the idea "this is a Thing. And a Thing contains these other subthings. " For example, a spaceship class, which contains both a Gun and a keyboard control. You write This-and all ' s well-and-good, until your boss says he wants mouse control instead of keyboard. So, go back and re-write the spaceship class. But wait a second. Your spaceship class didn ' t really change any. It's the control that changed. So why is you re-writing spaceship?

Instead of writing the controls right to the spaceship class, you could create a Mousecontrol class and use that. But if spaceship includes a reference to the Mousecontrol class, you ' restill directly binding. In order-to-change from Keyboardcontrol to Mousecontrol (and back again, when your boss changes he mind), you had to Cha Nge the reference inside spaceship.

Strange's binders make it possible to create indirect bindings this relieve your code ' s reliance on other parts of the pro Gram. This was a fundamental (but often misunderstood) tenet of object-oriented programming. Your code isn ' t really object-oriented until the objects themselves can function without reliance on other concrete Classe S. Using binders can give your code lots more freedom and flexibility. The structure of a binding

The structure of the binding, STRANGEIOC has two necessary modules and an optional module, the required module is a key, and a value, with this key to trigger this value, so the event as a key trigger callback function,

Let's look quickly on the structure of a single binding. This structure are repeated throughout Strange and all their extensions, so you'll want to understand the pattern.

A Strange binding is made up of the required parts and one optional part. The required parts is a key and a value. The key triggers the value; Thus an event can is the key that triggers a callback. Or the instantiation of one class can be the key, leads to the instantiation of another class. The optional part is a name. Under some circumstances, it's useful to qualify and bindings with identical keys. Under these circumstances, the name serves as a discriminator.

Several different binding methods are available with generics, types, and support for basic data types

All three of these parts can is structured in one of the ways, either as a value or as a type using C # generics. Using generics, for example we might say:

Bind<spaceship> (). To<liberator> ();

The ' Bind ' is the key, the ' to ' is the value. We might express the binding as a value:

Bind ("Meaningoflife"). to ();

A Binder fed with the-input "meaningoflife" would react with the output 42.

There is times when these-styles get mixed:

Bind<spaceship> (). to ("Enterprise");

When this binder was fed with the Type spaceship, it outputs the string value "Enterprise".

When naming are called for, the binding looks much the same:

Bind<icomputer> (). To<supercomputer>(). ToName ("Deepthought"); Finally, note that the following things is all the Same:bind<IDrive> (). To<warpdrive>(); Bind (typeof(IDrive)). to (typeof= bind<idrive>(); binding. to <WarpDrive> ();

The author also said that differentiation is only a grammatical sugar, so look at the overall interface layer and then see the implementation

The differences is nothing more than syntactical sugar.

There is countless forms of binding, and Strange gives you access to a few really useful ones. What's more, the binding framework was so simple that you can extend it yourself to create new binder components. We go into each of the included binders in the following section.

A period of time this cock in the New year state completely can not find the north, and today began to formally reply full blood work state, in addition if this cock article is you read me deeply honored, there is a point I want to explain is do not think I translate things less, I basically is full text read only write non-translation not the essence of the part, The rest of the section you have to read the original text can actually not make much sense.

Learn strangeioc–binding together with Keyle

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.