encapsulation

difference between abstraction and encapsulation?

What is the precise difference between encapsulation and abstraction? ...

Java: how to handle a LOT of fields and their encapsulation cleanly?

Let's say I am tasked with coding some kind of an RPG. This means that, for example, I'll want to track a Character GameCharacter and stats thereof, like intelligence, damage bonuses or hitpoints. I'm positively scared that by the end of the project I may end up with handling with very a high number of fields - and for each I would have...

C++ Header file that declares a class and methods but not members?

Is it possible to make a C++ header file (.h) that declares a class, and its public methods, but does not define the private members in that class? I found a few pages that say you should declare the class and all its members in the header file, then define the methods separately in you cpp file. I ask because I want to have a class th...

Do objects encapsulate data so that not even other instances of the same class can access the data?

In Java, Do objects encapsulate data so that not even other instances of the same class can access the data? Only when the keyword "private" is used? What are "accessor methods" in Java - methods like getName()? Thanks ...

Why is java secure coding important?

I'm having trouble understanding why java secure coding is important. For example, why is it important to declare variables private? I mean I get that it will make it impossible to access those variables from outside the class, but I could simply decompile the class to get the value. Similarly, defining a class as final will make it impo...

Tetris and pretty graphics

Say you're building a Tetris game. As any proper programmer, you have your view logic on one side, and your business logic on the other side; probably a full-on MVC going on. When the model sends its update(), the view redraws itself, as expected. But then... if you wanted to add, say, an animation to vanish a line, how would you imple...

Return concrete or abstract datatypes?

I'm in the middle of reading Code Complete, and towards the end of the book, in the chapter about refactoring, the author lists a bunch of things you should do to improve the quality of your code while refactoring. One of his points was to always return as specific types of data as possible, especially when returning collections, iterat...

How to encapsulate database access?

I am developing a transactional application in .NET and would like to get some input on how to properly encapsulate database access so that: I don't have connection strings all over the place Multiple calls to the same stored procedure from different functions or WORSE, multiple stored procedures that are different by a single column ...

Is it worth wrapping a logging framework in an additional layer?

I'm currently looking at upgrading the logging mechanism in a medium-to-large-sized Java codebase. Messages are currently logged using static methods on a Debug class, and I have recommended switching from this to something like SLF4J or commons-logging. The application architect prefers that I encapsulate the dependency on SLF4J (possi...

What is encapsulation with simple example in php?

What is encapsulation with simple example in php? ...

Must Dependency Injection come at the expense of Encapsulation?

If I understand correctly, the typical mechanism for Dependency Injection is to inject either through a class' constructor or through a public property (member) of the class. This exposes the dependency being injected and violates the OOP principle of encapsulation. Am I correct in identifying this tradeoff? How do you deal with this ...

How is assembly language incorporated into a program?

I have read in a lot of places that assembly language is not usually used to create complete programs, but is used by other programs to make certain procedures more efficient, particularly the ones that are called a couple thousand times a second. I am wondering how small bits of assembly code are incorporated into larger programs. I ...

Can I use private instance methods as callbacks?

My particular scenario involves doing some text transformation using regular expressions within a private method. The private method calls preg_replace_callback, but is seems that callbacks need to be public on objects, so I'm stuck breaking out of the private world and exposing implementation details when I'd rather not. So, in a nutsh...

C#: How to cleverly design a GUI for a Desktop Application with encapsulation in mind

Hey everyone! I am developing a desktop application with a MainForm that's grown rather large. There are lots controls in several containers on different levels (SplitContainers, TabPages, Panels). Now I want to refactor this class by separating all the controller code responsible for data binding & clearing the controls or carrying ou...

Is there a way to make a value accessible only to the parent of a nested class VB.NET?

In general, according to the OOP paradigm, my understanding of encapsulation basically says: If a member is private, it can only be accessed by the class. If a member is protected, it can only be accessed by the base class and any derived classes. If a member is public, it can be accessed by anyone. If I have a nested class, can I de...

Inheriting and encapsulating collection classes in Java

Suppose I have the following types of data: class Customer { String id; // unique OtherCustData someOtherData; } class Service { String url; // unique OtherServiceData someOtherData; } class LastConnection { Date date; OtherConnData someOtherData; // like request or response } Now I need to remember when each of the cust...

How often do you see abuse of C# shorthand getters/setters?

In C# you can create getter/setters in a simpler way than other languages: public int FooBar { get; set; } This creates an internal private variable which you can't address directly, with the external property 'FooBar' to access it directly. My question is - how often do you see this abused? It seems like it has a high potential to v...

C++ Encapsulation Techniques

I'm trying to properly encapsulate a class A, which should only be operated on by class B. However, I want to inherit from class B. Having A friend B doesn't work -- friendship isn't inherited. What's the generally accepted way of accomplish what I want, or am I making a mistake? To give you a bit more color, class A represents a com...

Proper application of access modifiers

I'm a student looking for resources which can help me further understand how to properly apply access modifiers to members/types as I code them. I know (in C#) what restrictions access modifiers like private, public, protected, etc. put into place. When I code my own little projects I have a tendency to just make everything public. I'm ...

How can/should C++ static member variable and function be hidden?

m_MAX and ask() are used by run() but should otherwise not be public. How can/should this be done? #include <vector> class Q { public: static int const m_MAX=17; int ask(){return 4;} }; class UI { private: std::vector<Q*> m_list; public: void add(Q* a_q){m_list.push_back(a_q);} int run(){return Q::m_MAX==m_list[0]->a...