encapsulation

Java: Subpackage visiblity?

I have two packages in my project: odp.proj and odp.proj.test. There are certain methods that I want to be visible only to the classes in these two packages. How can I do this? EDIT: If there is no concept of a subpackage in Java, is there any way around this? I have certain methods that I want to be available only to testers and other ...

object-private Vs class-private

Is there a notion of object-private in any OOP language ?? I mean more restrictive than the classic private access ? Private (or class-private) restricts the access to the class itself. Only methods that are part of the same class can access private members. object-private : restricts the access to the object itself. Only methods objec...

Asp.Net: Returning a Reader from a Class

Hi all, I was just wondering about the correct way to return a reader from a class? My code below works, but I'm unsure if this is correct. Also. I can't close the the connection in my class method and still access it from my ascx page, is that OK? // In my class I have the following method to return the record/reader -- it's a si...

Does dependency injection increase my risk of doing something foolish?

I'm trying to embrace widespread dependency injection/IoC. As I read more and more about the benefits I can certainly appreciate them, however I am concerned that in some cases that embracing the dependency injection pattern might lead me to create flexibility at the expense of being able to limit risk by encapsulating controls on what ...

How to encapsulate an array in Java

Hi, i'm starting with Java and i'm learning about setters,getters and encapsulation. I have a very simple program, 2 classes: Container has a private int array (numArray) with his setter & getter. Main creates a Container object and uses it in totalArray method. public class Container { private int numArray[]= {0,0,0}; pub...

C# - Design-related dispose question (take two)

I asked a question earlier today, but I think I need to approach it in a different way (on top of that there was a "hang up" in regards to DataSet). Here's a class that encapsulates the creation of a Font (in other words, it is reading data from an xml file and is creating a font, at runtime, based on what it reads from that file): pub...

Unit testing and encapsulation

I'm trying to get into unit testing, but there's one thing bothering me. I have a php class which I want to unit test. It takes some parameters, and then spits out HTML. The problem is that the main functionality is calculating some values and conditions, and these I want to test. But I have put this in a private method, because normall...

Where do you put unit tests for private methods?

Where do you put unit tests for private functions in C# classes? An article in Wikipedia suggests: Putting tests in the same class as the members they're testing Using partial classes Personally, neither of these methods seem appropriate, and I much prefer to have unit tests located in a separate project altogether. Any thoughts on...

What's the most appropriate way to expose lists inside a class?

Imagine the following model: A Table has many Rows A Row has many Cells What would be the preferable interface to deal with these classes in a "object oriented way"? 1 - Provide access to the properties rows / cells (Not necessarily exposing the underlying data structures, but creating for example a class RowCollection...) my_table...

Why stick to get-set and not car.speed() and car.speed(55) respectively?

Apart from unambiguous clarity, why should we stick to: car.getSpeed() and car.setSpeed(55) when this could be used as well : car.speed() and car.speed(55) I know that get() and set() are useful to keep any changes to the data member manageable by keeping everything in one place. Also, obviously, I understand that car.speed() and car.s...

Widget encapsulation in JavaScript frameworks

I am looking for a JavaScript framework that provides encapsulation of UI widgets, and allows the developer to define composite widgets. In particular, I need to be able to take a widget, clone it, and place it somewhere in the document, and the widget should take care of managing any subwidgets and of keeping matching DOM objects and Ja...

Fine to have variables in a namespace?

I have a set of functions that work on a file. Originally I made it into a class, with the only private member being a static const std::string which was the name of the file. The user used these functions by creating an object and calling functions from it. However, I think I'm going to switch to using a namespace, since it's just a set...

c# parent-child property protection

Hello, Here are two classes with a parent/child relation (taken from Unity3D) public class GameObject { ... public T AddComponent<T>() where T : Component; ... } public class Component { ... public GameObject gameObject { get; } ... } Since only the getter is public, how do they acheive to set the value of ...

How to encapsulate image files into emails ?

Hi, Can someone explain me how to create "simple" email with embedded images files ? I know that there are tons of RFC that explain it but I don't really succeeded to do it. I have to build the body text of the email programmatically, without using any framework. Don't ask me about the language is used... Images are base64 encoded. Co...

Pimpl idiom: What size_type to use if implementation is unknown?

I have a class that holds an array of elements, and I want to give it a GetSize member function. But what return type should I give that function? I'm using the pimpl idiom, and so in the header file it is not known what the implementation will use to store the elements. So I cannot just say std::vector<T>::size_type, for example: cla...

Swiz mandates weak encapsulation.

I just started using Swiz, and, it seems like Swiz forces you to create classes with weak encapsulation. Swiz requires all event handlers to be public in order to mediate events. Assume that component 'A' dispatches a few events, which I want to listen to in component 'B'. Traditionally, I'll just add event listeners on 'A' in 'B' and a...

SQL Server: How to permission schemas?

Inspired by various schema related questions I've seen... Ownership chaining allows me to GRANT EXECUTE on a stored procedure without explicit permissions on tables I use, if both stored procedure and tables are in the same schema. If we use separate schemas then I'd have to explicitly GRANT XXX on the the different-schema tables. The ...

In C++ when should someone make a private function virtual?

Possible Duplicate: Why would a virtual function be private? I've seen private virtal functions declared here and their in C++ but I'm not entirely sure as to its purpouse design wise, are their any cases where it is beneficial to have a private virtual function? ...

vector size_type and encapsulation

I have a class with a private data member of type vector< A*>. The class has two public methods that actually use vector::size_type: Method returning number of elements in the vector Method returning element in the vector by index I can add to public section of the class the following typedef: typedef vector::size_type SIZE_t; ...

Why use getters and setters

Why use getters and setters? ...