A methodology that enables a system to be modeled as a set of objects that can be controlled and manipulated in a modular manner

learn more… | top users | synonyms (3)

1
vote
2answers
53 views

Design of object alias

Suppose you develop an interpreter or file system. There are objects, like variables, procedures and files in some environment. They have a name and content (variable has current value, procedure has ...
1
vote
1answer
39 views

How to compute Pricing of Product & Options based on User Option Selection and Pricing per Option

I am building a service for pricing options of a product and for pricing the product itself when product has various options. Example User selects some X options out of Y options available, where X ...
-2
votes
2answers
112 views

How do you hash 4 doubles into a size_t?

I have bounding boxes the key type. Box { double mins[2]; double maxs[2]; } And I want to have Box as the key type in the D programming language, so I have to implement: size_t toHash() const ...
1
vote
0answers
65 views

Change object state in different point in program

This is not about whether or not getters/setters are wrong. I understand its impact to encapsulation and that question has been raised here and SO several times already. I also do not want to just ...
0
votes
1answer
84 views

Is it possible to detect misuse of passing self type argument in compile time?

I just hit the very basic problem in OOP and I cannot see any working solution except postponing appropriate check until run time. It is pretty clear notion of an action "do something with value of ...
2
votes
1answer
209 views

When mapping from a database, do OOP objects (entities) need to store the database values in attributes?

When it comes to OOP where an external database is being read from and written to, is it necessary to have attributes/properties within the objects to store the data? Or is it enough to simply read ...
-1
votes
0answers
45 views

What classes should I use for API -> logic -> API?

I need to fetch some information from an API, parse through it and push the relevant data to another API. How should I design this? One class handling everything? One class per API and one for the ...
-2
votes
1answer
48 views

Entity validation in DDD [on hold]

I am always curious how the validation is done for the following: Attribute/Property validation. Using preconditions/invariant/postcondition? for value object use self-encapsulation. Validating an ...
0
votes
0answers
100 views

What is missing in my (mis)understanding of OOP? [on hold]

As far as I currently understand Object Oriented Programming, every instance of any variable type is an Object. So, every distinct variable (data) type--such as int, bool, or string--is a different ...
1
vote
3answers
138 views

When and why would you extract an abstract method from an abstract class to an interface?

I have been asked the following question in an interview: "What is the need of an interface when you can have an abstract method within an abstract class?" Which I did not know the answer to. Could ...
0
votes
0answers
29 views

How can I paint a custom circular JComponent without an “invisible box” around it? [migrated]

I'm writing a JApplet that displays a diagram with numbers in circles and lines connecting the circles. I've created a class that extends JComponent to act as the circles. I overrode the ...
2
votes
1answer
69 views

Child class accessing its parent's method from Ancestor method

I find myself right now banging my head with the following issue (in PHP): I have an abstract base class, which has a non-abstract method, inherited and unchanged all over the inheritance chain ...
4
votes
1answer
109 views

Which C++ IO interfaces for a complex data source i.e. converter

My question: When you've got a complex converter like, that takes chunks or large result sets out of a database, converts it into a line by line file/resource in the end, should one either design it ...
0
votes
1answer
47 views

Impacts of a method's parameter that throws an exception according to object state [on hold]

I'd like to know how bad it is to do something like this: public class FooBar { public bool CanOverride { get; } public FooBar(bool canOverride) { CanOverride = canOverride; ...
3
votes
2answers
293 views

Is turning a method into a class to use it across many classes bad practice? [closed]

Let's say I have a sort method inside of my class and another class that has no relationship with that class needs the same method. Instead of writing that method twice and breaking the do not repeat ...
1
vote
2answers
57 views

Does my code still break encapsulation and uses getters/setters instead of the TellDontAsk principle?

I and one guy have been discussing potential solution of a problem on an unrelated board, regarding the typical getter/setter hate, ie. using getters/setters leads to procedural programming. I ...
1
vote
2answers
104 views

A generic helper class, a project specific class, and the rest of project

I have a generic helper class (1) that can be used in other projects also. Imagine something like basic handling of file and folders, something useful and DRY that always come in handy. I have ...
1
vote
1answer
92 views

Compiler design prevent register override

I'm trying to write a compiler for a self-designed CPU with accompanying instruction set. The CPU has 3 registers, 2 input registers (B and C) and one output register (D). When for example an ADD ...
1
vote
2answers
132 views

Cleanest way to expand a base class without explicitly mapping properties in C#

Lets assume I have following base class: public class Base { public int Id {get; set;} public string SomeText {get; set;} public string SomeOtherText {get; set;} public static Base ...
0
votes
1answer
99 views

How to implement strategy pattern on N-Tier application?

Well, i have a N-Layer MVC project which is something like: Domain > Repository > Application > Presentation I have a feature on the website where the user put some monthly expenses (food, gas, ...
3
votes
0answers
81 views

Finite state machine menu design

I'm creating a FSM in python (it's a step sequencer and sample pad based on a Raspberry Pi 2). Right now there are two states and the third is the Menu. This is handled by a class System which ...
3
votes
1answer
204 views

How can a object have many types?

I am currently reading Design Patterns - Elements of Reusable Object-Oriented Software. I am in chapter 1 at page 16 in section Class versus Interface Inheritance. There in the last line of the page ...
1
vote
2answers
103 views

Does an interface including several methods that return instances of Object make sense?

I am in the process of writing my first true API. In the process, I am defining an interface for mapping complex data structures onto other complex data structures. At the moment, the interface ...
28
votes
8answers
6k views

Is it acceptable to copy and paste long but straightforward code instead of wrapping them into a class or function?

Suppose I have a segment of code to connect to internet and show connection results like it: HttpRequest* httpRequest=new HttpRequest(); httpRequest->setUrl("(some domain .com)"); ...
1
vote
3answers
232 views

Java need to call many methods systematically

I have a group of methods that is going to be very large. I need to be able to call methods systematically from a large group, in two different ways. The methods create a new item object with ...
2
votes
3answers
156 views

Why does the overriding rule of C++ not care about visibility changes?

In C++, it is possible to write an overriding for a base class's method even if the visibility declaration of the two don't match. What are the possible design considerations under the decision of not ...
-3
votes
1answer
154 views

I think fan-in fan-out is backward, please explain [closed]

The term Fan-In came from Electronics, and refers to how many inputs a logic gate has, such as a Two-Input AND gate (fan-in of 2). Fan-Out refers to how many gates can simultaneously draw on the (one ...
24
votes
5answers
3k views

Is it a good practice to avoid constants by using getters?

Is it a good practice to replace constants used outside of classes by getters? As an example, is it better to use if User.getRole().getCode() == Role.CODE_ADMIN or if User.getRole().isCodeAdmin()? ...
0
votes
1answer
93 views

Can I enforce the overriding of GetHashCode() and Equals() methods for users of a generic container class?

I have a container class similar to the one below (with much of the logic omitted): class Container<T> { Dictionary<T, TWrapped> contains = new Dictionary<T, TWrapper>(); ...
2
votes
4answers
211 views

Handling Multiple Collections in C#

I'm currently trying to learn C# and want to enhance my understanding of Object Oriented Programming (OOP). I'm hoping to accomplish this by experimenting with a small program that keeps track of my ...
1
vote
3answers
44 views

How to decide what instance variables to have in a class?

Most OO guides say not to store things in instance variables if they can be easily calculated, because the state might become inconsistent, and there is more code to maintain. I am trying to come up ...
25
votes
8answers
5k views

Is it a good practice to use List of Enums?

I am currently working on a system where there are Users, and each user have one or multiple roles. Is it a good practice to use List of Enum values on User? I can't think of anything better, but this ...
6
votes
1answer
109 views

Software design: recommend approach to avoid slicing/type erasure here

Here is a concrete minimal example to formulate my question : In small ball game, you have a physics engine that moves the objects regularly: void move(set< PhysicalObject* > objets, Duration ...
8
votes
4answers
370 views

Parallel hierarchies - partly same, partly different

There are quite a few similar questions out there 1, 2, 3, 4, but non seems exactly the case in this question, nor do the solutions seem optimal. This is a general OOP question, assuming ...
2
votes
3answers
195 views

What means mapping in terms of programming

My question is what means a mapper and the action of mapping something? For example, I often hear things like: Mapping the classes Mapping the objects from the database Mapping the objects Mapping ...
2
votes
1answer
50 views

Using prototype/non-Spring managed beans in Spring Web application

I have been working on few web applications/REST web services recently (Spring IoC/MVC/Data JPA etc) and they usually follow the same pattern: Controller classes --> Service classes (which have number ...
0
votes
1answer
61 views

static method, helper function or in the controller, where does this go?

I'm working on a piece of functionality that simply allows a guest user to perform an action a certain number of times before requiring them to login\create account. In this instance, they can vote on ...
1
vote
1answer
59 views

Modeling specific objects interaction

I want to model an interaction between classes, e.g. there is a general class Hero and he can have some items. (I came up with this analogy so it is easier to understand) Some of them are e.g. potions ...
0
votes
1answer
62 views

What is the difference between ADTs and objects? [closed]

This question was answered in a post here title "Understanding Abstract Data Types (ADTs) [duplicate]" (You need at least 10 reptutation to post more than 2 links...), and the top voted answerer (by ...
2
votes
3answers
180 views

C++ Virtual destructors used only when there are virtual functions

This is from Effective C++ (Meyers): Classes not designed to be base classes or not designed to be used polymorphically should not declare virtual destructors I don't understand why ...
0
votes
1answer
98 views

When to use “is a” or “has a”? [closed]

In my node.js application, I have a queue class which has push and pop methods and a data property. I have an Event class which handles an event and pushes it on to the queue. If I think object ...
9
votes
2answers
438 views

Interface Segregation Principle: What to do if interfaces have significant overlap?

From Agile Software Development, Principles, Patterns, and Practices: Pearson New International Edition: Sometimes, the methods invoked by different groups of clients will overlap. If the overlap ...
2
votes
1answer
39 views

How to implement Singleton on a Resource / ResourcesManager case?

This is a design pattern academic question exercise. We have a Resource class and a pure fabrication class ResourcesManager to manage objects w/ type Resource. The question is Given the following two ...
3
votes
2answers
174 views

Implementing “buy one get one for free” coupon logic for shopping cart

Trying to solve bogo coupon logic with proper design pattern, but having trouble identifying one. Use case: "Buy iPad get SmartCase for free" Suppose we have the following objects: Product: - ...
2
votes
2answers
151 views

is it bad practice that controller call repository instead of service?

is it bad practice that controller call repository instead of service? to explain more: I figure out that in good design controllers call service and service use repository. but sometimes in ...
2
votes
2answers
30 views

Exception Handling for class attributes in setters and constructors [closed]

I would like to discuss a question about best practices regarding exception handling (e.g. in Java). Normally, when setting the attributes of a class, I check the arguments in the setters for ...
56
votes
11answers
6k views

Does this class design violate the single responsibility principle?

Today I had an argument with someone. I was explaining the benefits of having a rich domain model as opposed to an anemic domain model. And I demoed my point with a simple class looking like that: ...
26
votes
11answers
3k views

Given a herd of horses, how do I find the average horn length of all unicorns?

The question above is an abstract example of a common problem I encounter in legacy code, or more accurately, problems resulting from previous attempts at solving this problem. I can think of at ...
0
votes
2answers
79 views

Which design pattern to choose when supporting multiple analytic tools?

I have spent quite some time learning all possible design patterns but I cannot find the ideal one for the following case. I am developing an iOS app where we are using multiple analytics tools like ...
-1
votes
1answer
41 views

SRP. Save to repository when edit. Internally or externally? [closed]

For example: class Data { private String field1; private String field2; public void someEditMethod() {} } class DataRepository { public void save(Data data) { // save to DB ...