0% found this document useful (0 votes)
9 views25 pages

Data Binding and Cohesion Metric

The document discusses data binding, its importance, and its relationship with cohesion and coupling in software development. It outlines various types of data binding, best practices, and metrics for measuring cohesion, emphasizing the significance of cohesive code for improved organization and maintainability. Additionally, it provides examples and tools for implementing data binding and checking cohesion in code.

Uploaded by

Ayesha Jalil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views25 pages

Data Binding and Cohesion Metric

The document discusses data binding, its importance, and its relationship with cohesion and coupling in software development. It outlines various types of data binding, best practices, and metrics for measuring cohesion, emphasizing the significance of cohesive code for improved organization and maintainability. Additionally, it provides examples and tools for implementing data binding and checking cohesion in code.

Uploaded by

Ayesha Jalil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 25

DATA BINDING AND

COHESION METRIC
GROUP 3

GROUP MEMBERS
ALIZA SAJID 15
SALEHA AFTAB 37
MISBAH IFTIKHAR 38
SIDRA TUL MUNTAHA 18
ALEENA HAMEED 17
AYESHA JALIL 16
RABIA AMIN 46
WHAT IS DATA BINDING?
• DATA BINDING
• Data binding is a way to connect and update data between different
parts of an application, like a website or a mobile app, so that they
always show the same information.
• Ensures that data is consistent and up-to-date across all connected
sources.
WHAT IS THE IMPORTANCE OF DATA
BINDING?
• IMPORTANCE
• Saves Time: Data binding automates the process of updating data, saving
developers time and effort.
• Reduces Errors: By automatically updating data, data binding reduces the
chance of human error.
• Improves User Experience: Data binding ensures that users see the most
up-to-date information, improving their overall experience.1.
• Increases Efficiency: Data binding enables developers to focus on other
tasks, increasing their productivity and efficiency.
• Enhances Data Consistency: Data binding ensures that data is consistent
across all connected sources, reducing inconsistencies and errors.
RELATION OF COHESION AND COUPLING
WITH DATA BINDING?
• COHESION :In data binding, cohesion is important because it
helps to ensure that the data and the UI components that
display the data are closely related and work together
seamlessly
• COUPLING : In data binding, coupling is important because it
helps to define the relationships between the data and the UI
components that display the data. Tight coupling can make it
difficult to change or replace one component without affecting
others, while loose coupling can make it easier to modify or
replace components independently.
BEST PRACTICIES FOR DATA BINDING

• Best Practices for Data Binding


• Use clear and consistent naming conventions
• Use data binding frameworks or libraries-
• Keep data binding logic separate from business logic-
• Use debugging tools to identify and fix errors
TYPES OF DATA BINDING
TYPES DEFINATION
• 1. One-Way Data Binding
• Definition: Data flows in one direction- from the data source (e.g.,
model) to the Ul (e.g., view).
• Use Case: Ideal for read-only scenarios where the Ul only displays
data without modifying it.
• Example: Displaying user details in a text field that doesn't allow
editing.1.
• 1. String Interpolation
• Definition: Embeds expressions or variables directly into the UI, often
using delimiters like {{ }}.
• Use Case: Simple one-way binding for displaying text.
• 2.Attribute Binding
• Definition: Binds a value to an HTML attribute (e.g., class, src, alt).
• Use Case: Used to modify element attributes dynamically.Example: Binding an
image URL to the src attribute.
• Use Case: Used to dynamically set element attributes.
• 3. Class and style binding
• Definition: Dynamically binds CSS classes or styles to elements based on
conditions or expressions.
• Use Case: Used to alter the appearance of elements.
• Example: React's className or Angular's [class.class-name].Each type of binding
has specific use cases, depending on whether you need one-way, two-way
communication, or event handling.
• Example: Angular's [property] syntax.
4. Property Binding
Definition: Data flows from the model to the view by binding to specific properties of Ul
elements.

2. Two-Way Data Binding


Definition: Data flows both ways-changes in the data source update the UI, and changes in
the Ul update the data source.

Use Case: Common in forms where user input updates the underlying model directly.
Example: Angular's ng Model directive or React with controlled components using state.

1. Event Binding
2. Definition: The Ul listens to events and triggers logic in the data layer, without directly
binding data to the Ul.
3. Use Case: Handling user interactions such as button clicks.
4. Example: Binding a button click to a method in JavaScript.
• Data Binding Examples and tools
• Reporting. Binding is a common way to compile reports that display data from a data source to a screen or
printer.
• Data entry. Data binding is also a common way to enter large amounts of data and keep it updated and
synchronized to a data source.
• Lookup tables. Lookup tables are information tables that are typically a part of larger data displays. Data
binding and controls are used to display and change data.Master-detail formats. This is a model for
communication protocols where one device or process controls another. These formats may have two
tables of data bound together.
• Data binding tools

• Visual Studio is a Microsoft product that provides design tools for working with custom objects as a data
source in applications. Visual Studio is also used to bind UI controls.
• Binding Library is a support library for Android developers that binds UI components to data sources.
• Google Web Toolkit is an open source tool from Google that enables web developers to create and
maintain browser-based Java applications deployed as JavaScript. Google Web Toolkit has a feature called
UiBinder that allows the creation of UIs.AngularJS is an open source JavaScript web framework that
facilitates the development of single-page applications. The framework uses HTML and two-way data
binding to synchronize data providers or data consumers automatically. As of January 1, 2022, Google is
• Code for illustrate late binding
• #include<iostream>
• using namespace std;
• class Base
• { public:
• virtual void show()
• { cout<<" In Base \n"; }
• };
• class Derived: public Base
• { public:
• void show() { cout<<"In Derived \n"; }
• };
• int main(void)
• { Base *bp = new Derived;
• bp->show(); // RUN-TIME POLYMORPHISM
• return 0;
• Code for illustrating early binding
• / Any normal function call (without virtual) // is binded early. Here we have taken base // and derived class example
so that readers // can easily compare and see difference in // outputs.
• #include<iostream>
• using namespace std;
• class Base
• { public:
• void show() { cout<<" In Base \n"; }
• };
• class Derived: public Base
• { public:
• void show() { cout<<"In Derived \n";
• }
• };
• int main(void)
• { Base *bp = new Derived; // The function call decided at // compile time (compiler sees type // of
pointer and calls base class // function.
• bp->show();
• Types of cohesion
• 1. Functional Cohesion: Binding elements that perform a single task.
• Example: Login function.
• 2. Sequential Cohesion: Binding elements that perform tasks in a specific order.
• Example: Payment processing.
• 3. Communicational Cohesion: Binding elements that operate on the same data.
• Example: Chat app.
• 4. Procedural Cohesion: Binding elements that perform a series of steps.
• Example: Recipe app.5. Temporal Cohesion: Binding elements that are related in time.
• 6. Logical Cohesion: Binding elements that are logically related.
• Example: Sorting algorithm.
• 7. Coincidental Cohesion: Binding elements that are unrelated but bundled together.
• Example: Utility app with calculator and unit converter.
• Importance of cohesion
• 1. Improved Code Organization: Cohesion helps to organize code into logical modules, making it easier to
understand and maintain.
• 2. Reduced Complexity: Cohesive code reduces complexity by breaking down large systems into smaller,
more manageable pieces.
• 3. Easier Maintenance: Cohesive code is easier to modify and maintain, as changes are localized to specific
modules
• .4. Reusability: Cohesive code promotes reusability, as individual modules can be reused in other contexts
• .5. Improved Readability: Cohesive code is more readable, as each module has a clear and specific purpose.
• 6. Reduced Coupling: Cohesion helps to reduce coupling, as each module is self-contained and independent.
• 7. Improved Scalability: Cohesive code is more scalable, as new modules can be added without affecting
existing code.
• 8. Better Error Handling: Cohesive code makes it easier to identify and handle errors, as each module has a
specific responsibility.
• 9. Improved Collaboration: Cohesive code promotes collaboration, as developers can work on separate
modules without affecting each other's work.
• 10. Reduced Bugs: Cohesive code reduces the likelihood of bugs, as each module is tested and validated
independently.
• Metric

• A metric is a way to measure something. It's a standard unit of measurement that helps us
understand how well something is doing or how well it's working.

• Cohesion Metric
• A cohesion metric is a way to measure how well the different parts of a program or system
work together. It shows how strongly related the different elements are within a module or
system.

• In simpler words, a cohesion metric helps answer the


question: "How well do the different parts of this program
fit together?"
• Cohesion metrics
• 1. LCOM (Lack of Cohesion in Methods):
• Measures the number of methods in a class that do not share any instance variables.
• - A low LCOM score (close to 0) means the methods in the class are cohesive and share instance
variables.
• - A high LCOM score (close to 1) means the methods in the class are not cohesive and don't share
instance variables.
• 2. TCC (Tight Class Cohesion): Measures the ratio of methods in a class that share at least one instance
variable.
• - A high TCC score (close to 1) means the methods in the class are cohesive and share instance
variables.-
• A low TCC score (close to 0) means the methods in the class are not cohesive and don't share instance
variables.
• 3. LCC (Loose Class Cohesion): Measures the ratio of methods in a class that do not share any instance
variables.
• - A low LCC score (close to 0) means the methods in the class are cohesive and share instance variables.-
• A high LCC score (close to 1) means the methods in the class are not cohesive and don't share instance
variables.
• 4. CBO (Coupling Between Objects): Measures the number of classes that are coupled to a given
class.-
• A low CBO score (close to 0) means the class is loosely coupled and independent.-
• A high CBO score (close to 1) means the class is tightly coupled and dependent on other classes.
• 5. RFC (Response For a Class): Measures the number of methods in a class that can be invoked in
response to a message.
• - A high RFC score (close to 1) means the class has many methods that can respond to messages.-
• A low RFC score (close to 0) means the class has few methods that can respond to messages.
• 6. ICH (Instance Cohesion): Measures the degree to which methods in a class share instance
variables.- A high ICH score (close to 1) means the methods in the class share many instance
variables.- A low ICH score (close to 0) means the methods in the class share few instance
variables.
• 7. MPC (Method-Parameter Cohesion): Measures the degree to which methods in a class share
parameters.-
• A high MPC score (close to 1) means the methods in the class share many parameters.
• - A low MPC score (close to 0) means the methods in the class share few param
• Cohesion metric formulas
• 1. LCOM (Lack of Cohesion in Methods):
• LCOM = (Number of methods that don't share instance variables) / (Total
number of methods)
• 2. TCC (Tight Class Cohesion):
• TCC = (Number of methods that share instance variables) / (Total number of
methods)
• 3. ICH (Instance Cohesion):
• ICH = (Number of instance variables shared by methods) / (Total number of
instance variables)
• 4. MPC (Method-Parameter Cohesion): MPC = (Number of parameters shared
by methods) / (Total number of parameters)
• Ways to check cohesion
• Manual Methods
• 1. Code Review: Manually review the code to identify cohesive methods and
variables.
• 2. Class Diagrams: Create class diagrams to visualize the relationships between
classes and methods
• .3. Sequence Diagrams: Create sequence diagrams to visualize the interactions
between methods.
• Automated Tools
• 1. Static Analysis Tools: Use tools like SonarQube, CodeCoverage, and CodePro to
analyze code cohesion.
• 2. Code Metrics Tools: Use tools like CodeMetrics, MetricsReloaded, and
SourceMonitor to calculate cohesion metrics.3. Integrated Development
Environments (IDEs): Use IDEs like Eclipse, Visual Studio, and IntelliJ IDEA to
• Best practices
• 1. Keep methods short and focused: Ensure each method has a single
responsibility.
• 2. Use meaningful variable names: Use descriptive variable names to
improve code readability.
• 3. Avoid God objects: Avoid creating large, complex objects that perform
multiple unrelated tasks.
• 4. Use design patterns: Apply design patterns to improve code organization
and cohesion.

You might also like