The tag has no wiki summary.

learn more… | top users | synonyms

-2
votes
1answer
71 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 ...
1
vote
1answer
270 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 ...
20
votes
6answers
1k 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 ...
3
votes
1answer
146 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 ...
4
votes
4answers
318 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 ...
7
votes
2answers
434 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 ...
1
vote
0answers
80 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
61 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
302 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
6answers
240 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 ...
5
votes
5answers
634 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
196 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
116 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
201 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
323 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
209 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 ...
3
votes
1answer
168 views

Should I assert in packages? [duplicate]

I have read a few asserts vs exception questions already; I ask specifically about package visible classes though. When you write a package, the classes marked with "public" are exposed to the ...
2
votes
3answers
217 views

Abstraction concept in OOP

I hear that Abstraction is a technique that helps us identify which specific information should be visible, and which information should be hidden. Encapsulation is then the technique for packaging ...
2
votes
4answers
105 views

To make a class function or not?

I'm wondering about functions used like this: object1->objectMethod1(arg1, arg2); if objectMethod1: - does not change the object state - does not use the object's state at all - is used by the ...
0
votes
1answer
187 views

Read-only class properties [duplicate]

When is recommended to use read-only properties -- if the language allows me? Are public read-only properties meant to replace getter methods or at least the Magic Methods like what is available as ...
3
votes
5answers
672 views

Why is Encapsulation considered a primary principle in OOP?

I am currently trying to understand more deeply the 4 principles of OOP: Abstraction, Encapsulation, Inheritance, and Polymorphism. After studying the four principles, I don't fully understand why ...
0
votes
2answers
116 views

Using interfaces as part of encapsulation

I'm creating interfaces for a number of our existing classes for mocking reasons. Many of these classes also have package scope methods as an attempt to give some level of encapsulation by ensuring ...
0
votes
0answers
42 views

Return compound structure from getter method in DTO

Suppose the following DTO class. Which of the two getters breaks encapsulation least? class Foo { public: /*Return the most primitive type. Caller do not need to worry about ...
0
votes
1answer
452 views

How to encapsulate method parameters in Java?

An HTTP query can be parametrized to a list of pairs like name=value that can be encapsulated in general as Map<String, String> since an HTTP GET query is string pairs. I could need something ...
0
votes
2answers
265 views

How do I make a domain model that doesn't violate OOP?

My game reads a number of JSON files, deserializes them, and hands the resulting objects off to the classes that need them. These deserialized objects, which can be thought of as the domain model, are ...
3
votes
3answers
406 views

How does accumulating large amounts of business logic on the model objects make building strong service contracts harder?

I heard a couple of times that putting business logic in database models is bad down the road. I just read this in blog of a Rackspace employee: The Django ORM also tended to have us accumulate large ...
9
votes
5answers
344 views

How to make it obvious that a function is being accessed from the outside?

This is a C specific question. I am trying to keep everything possible inside the translation unit boundaries, exposing only a few functions through the .h file. That is, I am giving static linkage to ...
2
votes
5answers
535 views

Should I use automatic properties?

I'm new to C# coming from a Java background. I'm working on a take home assignment for a coding interview. I normally write my code as following(Java): public class Test { //fields private ...
2
votes
4answers
257 views

Why do some projects have getters and setters for public instance variables?

I was looking into an open-source game framework project written in Java. It has several classes that: Have public instance variables. Have getter/setters for such variables. Generally, I write ...
10
votes
5answers
1k views

Can I use Dependency Injection without breaking Encapsulation?

Here is my Solution and projects: BookStore (solution) BookStore.Coupler (project) Bootstrapper.cs BookStore.Domain (project) CreateBookCommandValidator.cs CompositeValidator.cs IValidate.cs ...
5
votes
2answers
466 views

Modularity and “encapsulation” in C

This applies to C (and probably to any other similar non-object oriented language). If I have a central data store and potentially concurrent access there are two ways I can see of protecting it. ...
9
votes
6answers
2k views

Why did Java make package access default?

I'm asking this question because I believe they did it for a very good reason and that most people do not use it properly, well from my experience in industry so far anyway. But if my theory is true ...
1
vote
4answers
358 views

Data duplication vs Encapsulating. Which design to use?

The problem that I face is how to combine encapsulating and optimal memory use. I can't show you my code and therefore explain it on extensive (I hope) example. Let's say we need to have a database ...
3
votes
1answer
732 views

What are the disadvantages of self-encapsulation?

Background Tony Hoare's billion dollar mistake was the invention of null. Subsequently, a lot of code has become riddled with null pointer exceptions (segfaults) when software developers try to use ...
4
votes
4answers
583 views

Are trivial protected getters blatant overkill?

Something I really have not thought about before (AS3 syntax): private var m_obj:Object; protected function get obj():Object { return m_obj; } private var m_str:String; protected function get ...
4
votes
2answers
180 views

Is excessive indirection and/or redundant encapsulation a recognized concept? [closed]

I'm curious if there's a series of tendencies or anti-patterns when programming whereby a developer will always locally re-wrap external dependencies when consuming them. A slightly less vague ...
4
votes
2answers
504 views

Why does Clojure neglect the uniform access principle?

My background is Ruby, C#, JavaScript and Java. And now I'm learning Clojure. What makes me feel uncomfortable about the later is that idiomatic Clojure seems to neglect the Uniform access principle ...
4
votes
4answers
326 views

Encapsulate standard C functions?

While studying the C programming language and learning safe practices, I'm inclined to write a layer of functionality over several parts of the standard library. This would serve two purposes: I ...
23
votes
4answers
1k views

Why Java doesn't make use of encapsulation with some classes?

My question is related with System.in and System.out classes (there might be others like those in the Standard library). Why is that? Isn't that a bad practice in OOP? Shouldn't it be used like: ...
3
votes
2answers
626 views

Encapsulation in Domain Driven Design models?

I am using EF Code First and I had a model like below. public class Account { [Required] public string AccountNo { get; set; } [Required] public decimal Balance { get; set; } } I ...
1
vote
1answer
59 views

Encapsulate downcasting when returning from a method

In chapter 24 of Code Complete the author says, in reference to encapsulate downcasting when returning from a method, "If a routine returns an object, it normally should return the most specific type ...
0
votes
1answer
301 views

Is there a proper way to allow access to private list by reference?

I'm trying to provide a by-reference getter to a list of objects in a class. My setup looks something roughly like this: class c_Container { public: c_Item* Get(int uid); private: c_Item ...
1
vote
2answers
275 views

Go with an object-oriented perspective [duplicate]

My OOP JavaScript question is at the very bottom if you want to skip my introduction. In an answer to the question Accessing variables from other functions without using global variables, there's a ...
3
votes
1answer
82 views

Should I write a wrapper within a manager object?

I have three classes that work together to do one function (from the perspective of the rest of my program). There is a little bit of set up between them, so, to make it easier for the rest of my ...
5
votes
2answers
431 views

Please explain object versioning in the nodejs module system

This question is about the persistance of variables across different modules in nodejs when they don't directly "require" each other, but do "require" a common ancestor. It is also the generalised ...
0
votes
2answers
233 views

Is it useful to use encapsulation in dynamic typed, interpreted programming language?

For what I know, encapsulation is useful because: if you use directly an attribute and change its type in a static typed language you have to change all the code that uses the class. On the ...
61
votes
13answers
6k views

Why is it a good idea for “lower” application layers not to be aware of “higher” ones?

In a typical (well-designed) MVC web app, the database is not aware of the model code, the model code is not aware of the controller code, and the controller code is not aware of the view code. (I ...
0
votes
2answers
63 views

Is it 'safe' to expect myClasses to agree not to only call package Scope methods from other Package scope methods?

The questions says it all, but a quick overview of the situation. I'm creating a Model which contains classes (all inherriting myObject) which have a large amount of interconnection. I want the ...
-1
votes
4answers
770 views

Immutable vs mutable object as returned parameter for class method [closed]

There is a class method (static method) in which I create and build some object. And for filling that object, I create it as mutable object. My mutable object is a subclass of immutable object. So ...
5
votes
3answers
1k views

How important is encapsulation? [duplicate]

As a student in programming, I learned that encapsulation is one of the most important principles of object-oriented programming. However, I only follow that principle when I feel like it suits my ...