A methodology that enables a system to be modeled as a set of objects that can be controlled and manipulated in a modular manner
1
vote
0answers
30 views
When should something be a class? And are my chosen classes good OO design?
My background:
I am new to programming. Python is my only programming knowledge. I program as a hobby, and I'm teaching myself by reading copious amounts of books.
I understand enough about OOP to ...
1
vote
2answers
141 views
when using dependency injection, should I always pass an interface
When using depending injection, you generally pass everything around as an interface (perhaps with the exception of primitives and strings). That allows you to easily chance the behavior, without ...
0
votes
1answer
84 views
Is this instance of mixing FP and OOP a good design?
I had a strange-feeling pattern come up in some code I was writing. In a project with user accounts, there was a lot of code that needed to do common things such as creating accounts, deleting them, ...
0
votes
0answers
54 views
The finer points of HMVC
I'm new to HMVC and whilst tutorials are great about dealing with the overall details of keeping modules separate and only letting controllers communicate, they aren't so great at explaining the ...
25
votes
5answers
2k views
IOC Containers break OOP Principles
What is the purpose of IOC Containers? The combined reasons for it can be simplified to the following:
When using OOP/SOLID Development principles, Dependency Injection gets messy. Either you have ...
0
votes
2answers
128 views
When I create an object, is fresh memory allocated to both instance fields and methods or only to instance fields
I have a following class
class Student{
int rollNumber;
int marks;
public void setResult(int rollNumber, int marks){
this.rollNumber=rollNumber;
this.marks=marks;
}
public void ...
0
votes
0answers
4 views
error LNK2019: unresolved external symbol? [migrated]
Firstly, I am beginner in c++ and Visual C++ (but not OOP). I am now trying to import Excel data to my data structure. What I have done is creating the structure(as class) in dataStructures.cpp along ...
1
vote
4answers
281 views
When to not use dynamic in C# [on hold]
I'm making a class similar to the following:
public class KeyValue
{
public readonly string key;
public readonly object value;
}
Value could be of any object type as a result of this ...
9
votes
4answers
487 views
Is it an overkill to wrap a collection in a simple class only for the sake of better readability?
I have the following map:
Map<Double, List<SoundEvent>> soundEventCells = new HashMap<Double, List<SoundEvent>>();
This HashMap maps double values (which are points in time) ...
-5
votes
1answer
60 views
Preventing a Javascript object function called twice [on hold]
I am trying to reuse an object but my function is getting called twice. Here is what I have:
var KEYBOARD = {
template: 'keyboard',
getkeyboard: function(){
console.log(this.template);
}
}
...
0
votes
2answers
45 views
Should `setX(Object o)` methods perform deep or shallow copies of objects?
My particular situation is related to Java, but I believe this is a more general OOP question than just Java programming.
The Question: Should "mutator" methods perform deep or shallow copies?
An ...
1
vote
1answer
110 views
C++ : Association, Aggregation and Composition [on hold]
I'm beginning to study OOAD and I'm having difficulty finding a C++ code example that'd illustrate how Association, Aggregation and Composition are implemented programmatically. (There are several ...
0
votes
0answers
69 views
Designing a simple file manager [closed]
I've been trying to come up with the best way to design my file manager for a project. I need to work with many file implementations and I have a File class made of 2 classes inside: Data and ...
2
votes
3answers
240 views
Could the creation of many methods in Java affect performance? [closed]
I was told by a colleague that in Java, the performance may be worse if we create more methods, stacking many methods calling over them in JVM, specially in a Java EE environment.
This seems to ...
1
vote
4answers
135 views
Domain model associations that do not required the behaviour of the associated object. How to model?
I've been struggling with this question for a while.
I'm specifically thinking within the object orientated domain model.
Let's say I have two entities. A supplier and a customer. There is a ...
-1
votes
0answers
56 views
“Resource center”: should the resources be exposed as public constants, or through getters?
I'm working on an application that has to do with music.
Since the beginning of the work on the app, I had a public class named MusicalResources. The class had public static final Notes and Chords. ...
1
vote
0answers
71 views
DataMapper for a MMO game plugin to send packets
I am working on an plugin for some game-server. The information about the plugin is not really necessary.
Few points you might find helpful to answer to this question:
The server
The server is ...
0
votes
5answers
340 views
Liskov Substitution and SRP Principle violation - how best to structure this scenario?
While learning SRP and LSP, I'm trying to improve the design of my code to comply best with both of these principles. I have an employee class that has a calculatePay method on it. Firstly, I believe ...
2
votes
1answer
195 views
Any OOP design pattern that is somewhat representative of all of the SOLID OOP design principles at play?
I'm trying to teach an object oriented design principles course (on SOLID) at a training institute. I also want to teach the students a few OOP design patterns such as factory, singleton and one ...
0
votes
1answer
102 views
Are there two type of associations between objects or are there just different representations?
I've been spending some time on 're-tuning' some of my OOP understanding, and I've come up against a concept that is confusing me.
Lets say I have two objects. A user object and an account object. ...
4
votes
1answer
114 views
Reducing dependency cycles and reducing coupling
I'm trying to learn how to produce quality object-oriented code and have been studying concepts like SOLID. I'm currently working on an entity-component-process system for a small game engine.
...
0
votes
1answer
284 views
Single responsibility: how does this code cause problems?
Given the following interface
interface Modem {
public void Dial(string pno);
public void Hangup();
public void Send(char c);
public char Recv();
}
Uncle Bob writes
However, ...
1
vote
2answers
135 views
How to let the outside world decorate my private field?
Imagine a simple Controller (as in process control) interface. I have some concrete classes, say PIDController, that implement it. I also have some decorator classes that extend these classes ...
3
votes
1answer
173 views
Redundancy caused by polymorphism
I have two chat rooms, one has administration behaviour, and one doesn't. I have factored out all of the common code into a base chat room, but the AdministerChatroom behaviour I have pulled out into ...
0
votes
1answer
71 views
Efficiency of getters/setters with database performance
I'm currently in the process of refactoring a very old personal project of mine, which used procedural PHP-in-HTML code. I'm modernising it as a learning project, using OOP where beneficial. I ...
2
votes
1answer
70 views
class hierarchy with structurally different subclasses
I want to implement a protocol layer which sits on top of the TCP/IP stack. There is a limited set of PDUs that can be sent and for each PDU there is a class which represents it in a structured form. ...
2
votes
5answers
503 views
Are a class's methods stored only once in memory? [closed]
When I create an instance of a class the system allocates memory for all instance variables of the class. Some languages may call them fields or properties.
But what about the code of the class ...
1
vote
1answer
125 views
Entity Component System Coupling
Lately I've been working on a small personal project which is basically an Entity Component System framework with autoupdated Systems.
While I have a pretty good idea on the way the framework should ...
0
votes
2answers
139 views
Designing Nested List<Class> Property in a Class
I'm currently in the class modeling phase of my project.
Real life Scenario:
Let's say I have a Project that is composed of Main Components and each Main Component is composed of Sub Components and ...
0
votes
2answers
172 views
C# - initialize variable inside method and use in whole class [closed]
this is a conceptual question, but if i initialize a variable in c# as public will it be able to be used in the class as I want a variable "player1" and a variable "player2" where either could be one ...
0
votes
1answer
49 views
The ViewController design in iOS vs MVC in tradiational web apps design
As I came from the background of webapps and move to iOS programming, I am wondering why we can't just apply the MVC design approach to native apps,
i.e. in iOS, the view and controller are tightly ...
2
votes
1answer
153 views
Composing programs from small simple pieces: OOP vs Functional Programming [closed]
I started programming when imperative programming languages such as C were virtually the only game in town for paid gigs. I'm not a computer scientist by training so I was only exposed to Assembler ...
1
vote
3answers
144 views
Am I violating LSP if the condition can be checked?
This base class for some shapes I have in my game looks like this. Some of the shapes can be resized, some of them can not.
private Shape shape;
public virtual void SetSizeOfShape(int ...
1
vote
2answers
260 views
Advice on approaching a significant rearrangement/refactoring?
I'm working on an application (hobby project, solo programmer, small-medium size), and I have recently redesigned a significant part of it. The program already works in it's current state, but I ...
4
votes
5answers
378 views
Questioning one of the arguments for dependency injection: Why is creating an object graph hard?
Dependency injection frameworks like Google Guice give the following motivation for their usage (source):
To construct an object, you first build its dependencies. But to build each dependency, ...
2
votes
1answer
165 views
Is this JS code a good way for defining class with private methods?
I was recently browsing a open source JavaScript project. The project is a straight port from another project in C language. It mostly use static methods, packed together in classes. Most classes are ...
1
vote
1answer
135 views
Dependency injection in constructor, method or just use a static class instead? [closed]
What is the best between:
$dispatcher = new Dispatcher($request);
$dispatcher->dispatch();
and
$dispatcher = new Dispatcher();
$dispatcher->dispatch($request);
or even
...
35
votes
5answers
4k views
Passing functions into other functions as parameters, bad practice?
We've been in the process of changing how our AS3 application talks to our back end and we're in the process of implementing a REST system to replace our old one.
Sadly the developer who started the ...
3
votes
1answer
148 views
Project structure: where to put business logic
First of all, I'm not asking where does business logic belong. This has been asked before and most answers I've read agree in that it belongs in the model:
Where to put business logic in MVC design?
...
2
votes
1answer
91 views
Models, collections…and then what? Processes?
I'm a LAMP-stack dev who's been more on the JavaScript side the last few years and really enjoying the Model + Collection approach to data entities that BackboneJS, etc. uses. It's helped me organize ...
1
vote
4answers
126 views
When should a method of a class return the same instance after modifying itself?
I have a class that has three methods A(), B() and C(). Those methods modify the own instance.
While the methods have to return an instance when the instance is a separate copy (just as Clone()), I ...
5
votes
6answers
494 views
Requesting feedback on my OO design
I'm working on an application that creates music by itself. I'm seeking feedback for my OO design so far. This question will focus on one part of the program.
The application produces Tune objects, ...
0
votes
3answers
137 views
How to change the state of a singleton in runtime
Consider I am going to write a simple file based logger AppLogger to be used in my apps, ideally it should be a singleton so I can call it via
public class AppLogger {
public static String file = ...
1
vote
0answers
75 views
JS closures - Passing a function to a child, how should the shared object be accessed
I have a design and am wondering what the appropriate way to access variables is. I'll demonstrate with this example since I can't seem to describe it better than the title.
Term is an object ...
3
votes
4answers
229 views
Is there a way to avoid type-checking in this scenario?
I have a class SuperClass with two subclasses SubClassA and SubClassB. I have a method in a different class which takes a SuperClass parameter.
The method should do different things depending on the ...
0
votes
1answer
149 views
Should I limit my type name suffix vocabulary when using OOP?
My co-workers tend to think that it is better to limit non-domain type suffixes to a small fixed set of OOP-pattern inspired words, e.g.:
*Service
*Repository
*Factory
*Manager
*Provider
I believe ...
0
votes
2answers
134 views
One boilerplate class or many similar classes?
Lets say I'm trying to model a variety of objects that are virtually identical, the only difference being their class variables. Am I better off creating one boilerplate class and just calling the ...
9
votes
4answers
437 views
Are first-class functions a substitute for the Strategy pattern?
The Strategy design pattern is often regarded as a substitute for first-class functions in languages that lack them.
So for example say you wanted to pass functionality into an object. In Java you'd ...
0
votes
1answer
84 views
What's a “Polymorphic method”?
Sometimes people use the phrase "Polymorphic method/function".
Does it mean:
A method that takes a Polymorphic type as a parameter, and performs some operation on it. By "Polymorphic type" I mean a ...
1
vote
1answer
166 views
Passing in config values to a method using SOLID principles
I have an email helper class that has a method that sends email:
private static class EmailHelper
{
public static void SendEmail(string from, string to, string subject, string message)
{
...