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)

0
votes
1answer
27 views

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

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 ...
1
vote
0answers
53 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
93 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
44 views

Impacts of a method's parameter that throws an exception according to object state

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
248 views

Is turning a method into a class too use it across many classes bad practice? [on hold]

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
55 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
91 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
90 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 ...
2
votes
1answer
62 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
97 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, ...
2
votes
0answers
79 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
202 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
102 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
231 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
150 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
152 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 ...
23
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
92 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
208 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
40 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 ...
24
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
105 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
354 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
191 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
48 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
57 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
61 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
177 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
433 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
165 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
143 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 ...
1
vote
0answers
35 views

Why is conditionally using an empty panel in Apache Wicket a bad practice?

When Apache released its list of best practices, they recommended avoiding the addition of an empty panel conditionally and gave the following example of what NOT to do: ...
3
votes
1answer
150 views

What is the origin of “Program to an interface, not an implementation”? [closed]

What is the origin of "Program to an interface, not an implementation" -- does it originate from Design Patterns, 1994, by GoF, or from a computer scientist or from some concepts in computer science ...
3
votes
6answers
146 views

If Class is to define attributes and methods, and Interface is to define (a set of) methods, then how to think of interface needing new attributes?

I thought a class is supposed to define, or give a blueprint, of attributes and methods for an object. And then, an interface is to provide a set of methods, as a contract for its clients. (and so a ...
2
votes
2answers
78 views

What is a proper way to implement object cloning with deep copy, using generally accepted OOP principles?

Short version of the question: What is a proper way to implement object cloning with deep copy, using generally accepted OOP principles? I ran into this while looking into the Prototype Design ...
5
votes
4answers
404 views

Does making a method static save memory on a class you'll have many instances of?

In response to Aaronaught's response to the question at: Can't I just use all static methods? Isn't less memory used for a static method? I am under the impression that each object instance carries ...
2
votes
2answers
99 views

Managing widgets in a simple GUI framework

So, I'm still working on my small GUI "library". (C++ with boost) The goal is to provide a simple solution for small SPI displays, using a Raspberry or some embedded board. Thus, I ended up having a ...
4
votes
1answer
83 views

Is Python's inheritance an “is-a” style of inheritance or a compositional style?

Given that Python allows for multiple inheritance, what does idiomatic inheritance in Python look like? In languages with single inheritance, like Java, inheritance would be used when you could say ...
4
votes
1answer
97 views

Using Python's Method Resolution Order for Dependency Injection - is this bad?

I watched Raymond Hettinger's Pycon talk "Super Considered Super" and learned a little bit about Python's MRO (Method Resolution Order) which linearises a classes "parent" classes in a deterministic ...
2
votes
1answer
100 views

Pass request as argument to service client vs. pass service client as argument to request [closed]

I need a design recommendation: I have a class that send a http request via another class WebServiceHandler() I am hesitating between the following two implementations, which one to choose?which one ...
13
votes
3answers
425 views

How wrong is it to talk about C++ “methods” (versus “member functions”)?

I understand that according to the C++ spec there is no such thing as a "method", and some (many? most?) C++ programmers consider "method" to be a Java-ism. On the other hand, even on a C++ forum ...