encapsulation

Does the ObjectDataSource just really suck?

I've never had the need to really ever use any of the .NET Data sources other than the SiteMap datasource however I'm trying to take advantage of the built in CRUD operations on a control which needs to be assigned a data source to correctly work. As I've been working through information online about implementing the ObjectDataSource an...

C++ Is private really private?

I was trying out the validity of private access specifier in C++. Here goes: Interface: // class_A.h class A { public: void printX(); private: void actualPrintX(); int x; }; Implementation: // class_A.cpp void A::printX() { actualPrintX(); } void A::actualPrintX() { std::cout << x: } I built this in to a stat...

encapsulation, data-hiding, setters/getters in c++

Possible Duplicate: Why use getters and setters? while writing class in c++, usually methods are made public, and attributes are made private/public, so that these attributes cant be accessed from outside. But when we use getters/setters, these attributes can be easily accessed,modified from outside. So, why to make them priv...

Should a class use its private members directly or its publicly exposed member functions?

Well, I'm not sure about this one. I have a class like class Object { int internalValue ; struct SomeStructType { int superInternalValue ; } someStruct ; public: int getInternalValue() { return internalValue ; } int getSuperInternalVa...

Container relationships and encapsulation

In my game engine I have a State class that represents the game world at a point in time. This State contains a number of Body objects that define one rigid body each. Each State has a container to keep track of the Body objects it owns, and each Body has a pointer back to its parent State. Outline of State class: class State { private...

Java Object Oriented Design Question: update internal state or return new object

This is a design question. The design is pseudo-code and represents a small example but I may add a lot more methods, data, logic in the future. In this example, I am considering two approaches. In the execute method below, should I return an immutable "data/bean/model" object with the output of the execute method or update the state ...

C++ private virtual inheritance problem

In the following code, it seems class C does not have access to A's constructor, which is required because of the virtual inheritance. Yet, the code still compiles and runs. Why does it work? class A {}; class B: private virtual A {}; class C: public B {}; int main() { C c; return 0; } Moreover, if I remove the default constr...

Should class methods accept parameters or use class properties

Consider the following class public class Class1 { public int A { get; set; } public int B { get; set; } public int GetComplexResult() { return A + B; } } In order to use GetComplexResult, a consumer of this class would have to know to set A and B before calling the method. If GetComplexResult accesses man...

when creating custom class to be used by LINQ, does it matter if it pure variable or should it always be properties?

what would be the difference between this class Class1 { public string prop1 { get; set; } public string prop2 { get; set; } public string prop3 { get; set; } public string prop4 { get; set; } } and this class Class2 { public string var1; public string var2; public string var3; public string var4; } ...

Should I pass in or encapsulate a connection in a DAO?

Is it better to encapsulate the connection inside a DAO, ie have the DAO create or retrieve the connection and then close, or is better to pass the connection into the DAO and handle the details in code external to the DAO? Follow-up: How do you mange closing connections if you encapsulate the connection inside the DAO? ...

How to hide specific type completely using typedef?

I have a quick question about encapsulating specific types with typedef. Say I have a class Foo whose constructor takes a certain value, but I want to hide the specific type using typedef: class Foo { public: typedef boost::shared_ptr< std::vector<int> > value_type; Foo(value_type val) : val_(val) {} private: value_type val_; }...

Access of private field of another object in copy constructors - Really a problem?

In my Java application I have some copy-constructors like this public MyClass(MyClass src) { this.field1 = src.field1; this.field2 = src.field2; this.field3 = src.field3; ... } Now Netbeans 6.9 warns about this and I wonder what is wrong with this code? My concerns: Using the getters might introduce unwanted side-effect...

[Java] Why is "length" attribute public in String class ?

Hi everyone, In Java, I'm wondering why the "length" attribute of the String class isn't private? Isn't it a bad practice according to encapsulation principle? Why is there no method like "getLength()" for instance? PS: Sorry for my English, I'm still improving it. ...

What is Encapsulation and how can it defend abstractions against corruption?

It's quoted from a report by Bjarne: Encapsulation – the ability to provide guarantees that an abstraction is used only according to its specification – is crucial to defend abstractions against corruption. Can someone explain this? Thanks ...

Is there any workaround for making a structure member somehow 'private' in C ?

I am developing a simple library in C, for my own + some friends personal use. I am currently having a C structure with some members that should be somehow hidden from the rest of the application, as their use is only internal. Modifying by accident one of this members will probably make the library 'go wild'. Is there any 'workaround'...

Writting a getter for a pointer to a function .

I have the following problem: "list.c" struct nmlist_element_s { void *data; struct nmlist_element_s *next; }; struct nmlist_s { nmlist_element *head; nmlist_element *tail; unsigned int size; void (*destructor)(void *data); int (*match)(const void *e1, const void *e2); }; /*** Other code ***/ What will b...

Encapsulating user input of data for a class (C++)

For an assignment I've made a simple C++ program that uses a superclass (Student) and two subclasses (CourseStudent and ResearchStudent) to store a list of students and print out their details, with different details shown for the two different types of students (using overriding of the display() method from Student). My question is abo...

respond_to? and protected methods

It may not be so obvious how respond_to? works in ruby. Consider that: class A def public_method end protected def protected_method end private def private_method end end obj = A.new obj.respond_to?(:public_method) # true - that's pretty obvious obj.respond_to?(:private_method) # false - as expected obj.res...

TDD and encapsulation priority conflict

Hi, I just started practicing TDD in my projects. I'm developing a project now using php/zend/mysql and phpunit/dbunit for testing. I'm just a bit distracted on the idea of encapsulation and the test driven approach. My idea behind encapsulation is to hide access to several object functionalities. To make it more clear, private and prote...

Why "private" methods in the object oriented ?

I understand it is a very basic concept in the oops. But still I cannot get my head around. I understood why member variables are private, so class user cannot abuse it by setting up invalid values. But how can this apply to the methods ? ...