Copyright

One-Way Data Binding vs. Two-Way Data Binding

Instructor: David Gloag
For this lesson, we'll concentrate on the concept of data binding by defining it, examining the one-way and two-way variations, and how we might choose one over the other.

The Trials of Software Development

Writing computer software has its challenges. When creating an application, programmers have to build connections to their data sources, they have to crunch the data into a form the application can use, and then they have to display the modified data to their users. A difficult proposition at the best of times. If that isn't enough, the data is often located half-way around the world, there is generally too much of it, and it has to be displayable on the various devices your users might employ, such as cell phones and laptops. Therefore, it would be nice if the process could be simplified somewhat. And indeed, it can. One way is through the use of data binding.

What is Data Binding?

Data Binding is the process of connecting information with displayable objects from a programmatic perspective. It is a kind of mapping that defines the endpoints of the connection, and handles the details of the connection for you. Consider your favorite word processor. It likely has a feature that allows you to change the font used for some selected text. If we assume that data binding is used to populate the contents of the font list, then the programmatic steps needed might look as follows:

  • Step 1: declare a variable that will hold the font list.
  • Step 2: assign that variable to an input source for the display control (likely a drop-down list or similar).
  • Step 3: query the operating system for the fonts available and load them into the variable.

The data binding takes care of the rest. You will magically see the list of fonts when you click the drop-down.

What is One-Way Data Binding?

One-way data binding is a situation where information flows in only one direction, typically from a data source to the control. This has the effect of making the variable read-only from the user's perspective. Anything they do with the control won't affect the information it displays. For the fonts example above, it would mean that the list of fonts wouldn't change. Well, not through the control at any rate. So, it provides a measure of protection against inadvertent changes (ie: the control is read-only).

What is Two-Way Data Binding?

Two-way data binding is when information flows in both directions, from data source to the control, and from the control to data source. This has the effect of allowing the variable to be updated by the user. Anything they do with the control will affect the information it displays and the information that gets stored. For the fonts example above, it would mean that you could add a new font to the list. An interesting feature to be sure.

To unlock this lesson you must be a Study.com Member.
Create your account

Register to view this lesson

Are you a student or a teacher?

Unlock Your Education

See for yourself why 30 million people use Study.com

Become a Study.com member and start learning now.
Become a Member  Back
What teachers are saying about Study.com
Try it risk-free for 30 days

Earning College Credit

Did you know… We have over 200 college courses that prepare you to earn credit by exam that is accepted by over 1,500 colleges and universities. You can test out of the first two years of college and save thousands off your degree. Anyone can earn credit-by-exam regardless of age or education level.

To learn more, visit our Earning Credit Page

Transferring credit to the school of your choice

Not sure what college you want to attend yet? Study.com has thousands of articles about every imaginable degree, area of study and career path that can help you find the school that's right for you.

Create an account to start this course today
Try it risk-free for 30 days!
Create an account
Support