The tag has no usage guidance.

learn more… | top users | synonyms

1
vote
1answer
58 views

Best practice for settings for PHP class for code generation [on hold]

I would like to have a class create any code from given options and output it in a chosen way. Background I have written class for generation of simple JavaScript code for such cases where is needed ...
1
vote
1answer
130 views

Javascript Closure Style Similar to Java Class Structure

PROBLEM: There is a coding imperative (S. McConnel, Code Complete) that one shouldn't code on language, but by means of it, e.g. doing right style things even if language doesn't have some ...
3
votes
1answer
129 views

Passing MVVM objects to other classes [closed]

So I'm using C# WPF and binding to a Model View to display states. The data that needs to be displayed is spread across a couple different classes. For instance I have a class that reads out digital ...
6
votes
4answers
306 views

Class design dilemma: Encapsulation vs Single Responsibility/Separation of Concerns

I'm working on a class that represents an object with multiple representations - one is an XML type representation used by an automatic ordering system, the other is a POJO-based representation used ...
1
vote
0answers
83 views

Having a globally static cached list without breaking encapsulation?

I have a couple wrappers around third party APIs that allow me to retrieve information from certain web services. Querying these services can be rather time intensive, so in my older version of my ...
1
vote
1answer
88 views

Setting up my inheritance model?

I'm working on refactoring a synchronization web app that our company uses. Currently it's merely a set of controllers that fire up a set of helpers that go through a long chain of if-else type ...
0
votes
1answer
110 views

Should I hold an Id and the Item [duplicate]

Let's say I have a Customer which contains an Address class like: public class Customer { public int Id { get; set; } public string FirstName { get; set; } public string LastName { get; ...
3
votes
1answer
113 views

A condition on an argument used in multiple calls of a method: enforced by caller or by the method?

Let's assume I have an object a of a class A. It has a method that needs an argument in form of another object of a particular type - but the argument should also be in particular state, because the ...
1
vote
2answers
92 views

How to mitigate complexity of fallbacks introduced to automatically retry upon failure?

So this may come off a bit broad and generalized, but after spending some time working around under developers, I've come to notice many different methods and design patterns. However, one big thing ...
0
votes
3answers
162 views

Difference of efficiency [duplicate]

I'm doing a compiler, and I'm using the System.out.println(); to print assembly; And the code get bigger, and more complicate to understand. I want to know whats is the difference of efficiency ...
0
votes
2answers
142 views

Meaning of using getters and setters and Uses of parameterized Constructor. [duplicate]

I am using getters and setters to for the purpose of encapsulation. public class Student { private String studentID; private String studentName; private String address; public ...
4
votes
2answers
130 views

Does returning pointer to composed objects violate encapsulation

When I want to create an object which aggregates other objects, I find myself wanting to give access to the internal objects instead of revealing the interface to the internal objects with passthrough ...
6
votes
6answers
2k views

What is the usefulness of private variables? [duplicate]

While I've never used a language that had built-in variable privacy, a book I'm reading by Douglas Crockford explains a way to create privacy in JavaScript, however it doesn't make sense to me so. The ...
2
votes
2answers
320 views

How is encapsulation broken by getters/setters, even when using MVC model [duplicate]

I was thinking about encapsulation in Java and then I thought how getters/setters break encapsulation. After I went through this , I saw many recommendations like to avoid getters/setters on fields ...
3
votes
3answers
305 views

'Encapsulation Vs Performance' trade-off in a lockable linked list

Main purpose of encapsulation is to protect in-variants of any class(in java). Here is the complete code for class DList/class lockDList/class DListNode/class LockDListNode. class DList and it's ...
3
votes
1answer
40 views

Abstract/encapsulating session superglobal usage inside common accessor class

I am in the process of removing direct dependencies from an existing project. I have now come to removing the direct use of $_SESSION inside scripts. This is to make the same scripts available for an ...
4
votes
3answers
215 views

Nested POJOs, exposing collections, detecting changes

I have a couple plain object classes to represent data read from a file. They look something like this: public class Command { private String name; private List<Message> messages; } ...
1
vote
1answer
104 views

If the representation part of type abstraction is declared private, then how does sub-classing violate encapsulation?

Here, I learned that sub-classing violates encapsulation: it violates encapsulation, since the implementations of the superclass and subclass become tightly coupled For instance, If we consider ...
0
votes
0answers
42 views

Abstracting AutoLayout sensibly - why is this so conceptually tough and where should I begin?

Below are some babbling, probably incoherent thoughts, but I am so stuck on this problem and I feel like an elegant solution is possible. Though it is indisputably awesome, and makes programatic view ...
1
vote
4answers
298 views

Why I need to make method of my class private, If I need to access it throughout my application?

I am going through the beginners tutorial for C# from a website http://www.homeandlearn.co.uk/csharp/csharp_s10p1.html On chapter of classes, it makes the method of class private and then use ...
0
votes
1answer
213 views

Access fields of super class from derived classes [duplicate]

There is an abstract BaseGame class that will be inherited by specific game classes. This class has an attribute requestHandler that will be used in all subclasses and should be initialized in the ...
85
votes
15answers
8k views

TDD Red-Green-Refactor and if/how to test methods that become private

as far as I understand it, most people seem to agree that private methods should not be tested directly, but rather through whatever public methods call them. I can see their point, but I have some ...
4
votes
4answers
186 views

Design question concerning proper and practical encapsulation

I have been working on refactoring old code and found a lot of instances of the following type of situation: There is a master object which we call "Application" and there is only one of these. The ...
0
votes
1answer
177 views

How much to encapsulate when objects being dealt with are pretty similar

As I have been answering questions related to object-oriented design and how to go about reducing the amount of classes to make sure that there is not a lot of "class clutter" and code repetition I ...
1
vote
2answers
524 views

Why am I getting field visibility warnings in Sonar?

Some static analysis tools flag non-private fields with Variable '[nameHere]' must be private and have accessor methods. Sonar consistently presents such warnings and wants to change all ...
6
votes
3answers
840 views

Can “higher order function” feature allow/maintain abstraction and encapsulation?

Below is the function repeat written using a functional paradigm, such that when called as repeat(square, 2)(5) it will apply the square function 2 times on the number 5, something like ...
7
votes
5answers
405 views

Should private functions be held to the same standards as public functions?

If I'm building private utility functions, should they be held to the same rigorous standards in terms of handling invalid data as public functions? Example:If I'm writing code to calculate the ...
4
votes
1answer
346 views

How can I use the “Non-Member Functions Improve Encapsulation” pattern from C#?

In 2000, Scott Meyers argued that non-member functions improve encapsulation. In C++, a non-member function is a C-style global function: ...
0
votes
2answers
118 views

Should methods perform checks that they accomplished the task they were built for? or should they just throw an exception?

What are some pro's and con's of validating your performed the task intended? public static bool UploadFile(string filename) { // 1. upload the file // 2. check to see if the file now exist ...
4
votes
1answer
111 views

Encapsulation: Should all properties be private and protected?

After learning about encapsulation in OOP, I started to use only protected and private properties, share data via accessors and change properties via mutators. Right now, I'm afraid of declaring ...
1
vote
2answers
127 views

Query on hiding implementation details in java

With the below piece of thread related code, I see that author of Thread class is hiding the details about the working of start() method. What a user of Thread class need to know is, class Thread ...
-2
votes
2answers
433 views

Why public access level method get overridden in java?

This question is raised with a clarification required to decide when to declare a method protected or public during class design of a package. My point is, if one needs to override a method of a ...
2
votes
3answers
211 views

Getters and Setters unclear example

I know autmatic getters and setters are considers bad as they tend to break object's encapsulation. They also move the work that should have been done within the object outside. Allen Holub is a big ...
-2
votes
1answer
142 views

Architecture - 3D Modeling Library

I'm writing a library to allow users to generate 3D models programatically. User writes code (e.g. Square(4)) User views preview of 3D model (with built in visualizer) User can "print" the model to ...
5
votes
1answer
441 views

How to store satellite data in C data structures

I've been reading through Introduction To Algorithms 3rd Ed, and I am having difficulty in implementing some practical situations. It's not the theory, or implementing the internals of the data ...
1
vote
1answer
291 views

Should ORM data access methods be wrapped or used directly?

We're using an internally-built ORM. Each table is represented by a Model class, which inherits from a base model class that has a handful of methods like GetAll, GetWhere (to get rows with specified ...
21
votes
6answers
2k views

Should I place functions that are only used in one other function, within that function?

Specifically, I'm writing in JavaScript. Let's say my primary function is Function A. If Function A makes several calls to Function B, but Function B is not used anywhere else, then should I just ...
4
votes
1answer
200 views

Implementing a Username Class

I am attempting to encapsulate several features about a user in a single class. Although the main use for this class would be to initialize it once and never have to call set any variables again, I ...
5
votes
4answers
380 views

Which language introduced the idea of private (hidden) variables? [duplicate]

I know C++ had private variables inside classes, and Java, C#, Javascript, and others picked up on that and ran with it. Aside from variable scope, most languages before that just made everything ...
8
votes
2answers
613 views

Why shouldn't I make variables public, but should use public getters/setters? [duplicate]

I'm watching a C++ tutorial video. It is talking about variables inside classes and assert that variables should be marked private. It explains that if I want to use them publicly, I should do it ...
2
votes
0answers
173 views

Having trouble with exposing class properties across projects

I have several projects in my solution: Logan.Web.DBContext defines the DbContext for the database and builds the data model Logan.Web.Objects defines the classes that will represent the tables in ...
1
vote
1answer
115 views

Public versus private inheritance when some of the parent's methods need to be exposed?

Public inheritance means that all fields from the base class retain their declared visibility, while private means that they are forced to 'private' within the derived class's scope. What should be ...
3
votes
1answer
533 views

How to maintain encapsulation with composition in C++?

I am designing a class Master that is composed from multiple other classes, A, Base, C and D. These four classes have absolutely no use outside of Master and are meant to split up its functionality ...
1
vote
5answers
268 views

“Default approach” when creating a class from scratch: getters for everything, or limited access?

Until recently I always had getters (and sometimes setters but not always) for all the fields in my class. It was my 'default': very automatic and I never doubted it. However recently some discussions ...
6
votes
5answers
893 views

Should I always encapsulate an internal data structure entirely?

Please consider this class: class ClassA{ private Thing[] things; // stores data // stuff omitted public Thing[] getThings(){ return things; } } This class exposes the ...
0
votes
4answers
248 views

Why encapsulate container variables? [duplicate]

I wasn't sure how to formulate the title, but there's something that's made little sense to me in OOP I understand the idea of encapsulation, which is to create a layer of protection, and ...
2
votes
1answer
225 views

What's the right OO way to create a counter/inventory class that works for both differentiated and undifferentiated countables?

You are writing a videogame about trading beans. Red beans, black beans, pinto beans, you name it. As everybody knows all beans are the same. You write the "Inventory" class for a trader in that ...
2
votes
1answer
324 views

Should we encapsulate everything in a try{} block in a Try object?

Why can't I make a class for a Try including what I try and then run that in the try {} block? Why is it impractical? class DBConnectTry extends Try { TryResponse response[] attempt(TryObject ...
2
votes
5answers
347 views

Relative encapsulation design

Let's say I am doing a 2D application with the following design: There is the Level object that manages the world, and there are world objects which are entities inside the Level object. A world ...
0
votes
0answers
389 views

Use a global variable, a singleton, or something else

Preface: I am working in PHP (Abandon hope all ye who enter here). Background: There exists a large set of global functions in PHP, a number of which are miscellaneous system calls, like sleep (and ...