answersLogoWhite

0


Best Answer

There is no problem with keeping data and methods separate. Encapsulating data with the methods that operate upon the data doesn't actually resolve anything, it merely helps us to express the relationship between the data and the methods in code. But we still require methods that are completely separate from the data. For example, a function that operates upon two different data types cannot be a member of both data types, it has to be separate from at least one of them.

The problem to which you allude is not the fact that data and methods are separate but the fact that the data itself is publicly accessible and can be modified by any function regardless of whether the function is a member of the type or not. The compiler cannot help us because user-defined types are user-defined; it has no knowledge of which operations are valid and which are not.

Encapsulation not only introduces the concept of member functions it also introduces the concepts of private, protected and public access, as well as the concept of friend functions. These concepts do not exist at the machine level, they only exist at the programming level and are simply an extension to the procedural programming paradigm. Behind the Scenes, the data is still public and the functions are still separate; calling a member function is merely syntactic sugar-coating for an ordinary procedure call.

Encapsulation essentially allows us to inform the compiler as to which functions may gain access to which data. This helps to eliminate many potential errors at compile time, but also reduces the amount of code we need to write by eliminating runtime checks that would otherwise impact upon performance. In short, the more the compiler knows about our user-defined types, the more it can help us to eliminate errors in our code, and encapsulation is just one of the tools we use to provide that information to the compiler.

User Avatar

Wiki User

6y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What was the problem with keeping data and methods separate?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is an appropriate method for maintaing confidentiality of private information obtained from human subjects?

keeping data in a password-protected database, storing images in a secured cabinet, and coding data or specimens and keeping the key to the code in a separate, locked drawer.


What is the risk of keeping a data disc?

What is the risk of keeping a data disc


What are the methods in collect data?

There are five different methods in collecting data. The methods in data collect are registration, questionnaires, interviews, direct observations, and reporting.


Conclusion on depletion of natural resources?

Methods of collection data depends upon (i) nature of problem, and (iii) time and money available. Mostly, data is collected through use of secondary source. If no such data is available from liberaries or on the internet, one has to collect primary data for which a number of methods are available such as observations, in-depth techniques, experiments and


What process is involved in in all methods of testing hypotheses?

Data Collection is involved in all methods of testing hypotheses.


What is research methodology what are the characteristics of good research?

It is the methods used to collect data. A good research should give solution to the problem statement.


What scientific methods?

problem research hypothesis experiment purpose procedure data result conclusion communicate your finding that is the song and the steps KK


What are the scientific methods in studying economics?

1 identify the problem 2 make assumptions or hypothesis 3 gathering of data and information 4 data analysis 5 making a conclusion and recommendation


What are the problems in data redundancy?

1. Wasted Storage Space. 2. More difficult Database Updates. 3. A Possibility of Inconsistent data. Note: A solution to the problem is to place the redundant data in a separate table, one in which the data no longer will be redundant.


What are the methods of presenting data?

two methods of presenting data 1.tabular form 2.pictorial form


How do you record keeping?

That is the correct spelling of "record keeping" (saving data).


What is a quartile in a math problem?

A quartile is a given section in a range of data. To find the quartile, you must first find the median. Then find the "median of the median", using these to separate your data into sections, giving you a total of four sections of data.