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
2answers
82 views
Too specific of namespacing/packaging
I'm about to start building a C# library for English and French morphology as a side project. The library will be later merged with other linguistic aspects (phonology, sentence parsing, etc). for ...
1
vote
1answer
128 views
How to decide if object should request or receive data?
Deciding whether an object should request data (by calling a function) or receive data (by having a function called from another object) is probably dependent on the exact situation. So how do I ...
-4
votes
0answers
31 views
I wrote a Java program to load and play an audio file, can anyone point out what the problem in the code is? [on hold]
package rico;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Rico extends JApplet {
private AudioClip sound1, sound2, currentSound;
private ...
1
vote
1answer
69 views
Structuring project (refactoring)
I'm working on a project that requires from me to make modular and extendible code structure. This code should be able to support multiple clients. The good news is that code should not do anything ...
3
votes
2answers
59 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 ...
5
votes
3answers
592 views
How come javascript, being a prototype based language, doesn't have an easy way to access the prototype?
May be this is a stupid question, but I'm kind of intrigued.
Being JavaScript a prototype based language, with its pseudo-class function constructors sort of half baked (remember JavaScript: The Good ...
0
votes
1answer
22 views
How can I create a data model to efficiently answer the question of - where to place my db-interaction code I am about to write?
I am seeking the right model for storing and retrieving data, when working with any specific class, while keeping in mind the bigger picture.
Details:
I have some SQL code in (one) of my classes and ...
2
votes
1answer
257 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
1answer
62 views
Cleanly using PHP Iterator class in Loops - calling first element
I have implemented the Iterator class in PHP and built the follow mandatory methods as follows
class I implements Iterator
{
private $a = [];
function __construct(array $a)
{
...
0
votes
1answer
91 views
Should I initialize a member variable in declaration when it is initialized by a constructor parameter?
Which is recommended for initialization of class fields in C#:
class Foo
{
public X x = new X(); // or any default value...
public Foo(X _x)
{
x = _x;
}
}
Or
class Foo
{
...
2
votes
1answer
223 views
Change routing to comply with Law of Demeter
I have a Task, Owner and Plan. Charge values are kept in a plan, owner is on a particular plan and task knows its owner.
A task needs to setup its charges based on the knowledge the owner has. Owner ...
2
votes
1answer
174 views
Hidden dependencies - why not?
Hidden dependencies:
function __construct($dep_registry){
$this->db = $dep_registry->get('db');
$this->request = $dep_registry->get('request');
...
}
Not so hidden:
function ...
3
votes
3answers
130 views
Development Time: sql in UI code vs domain model with datamapper
First, sorry for my English guys.
Currently this is my first programming job. I am labeled as the most incompetent programmer in my company that's because they measure the performance and ...
3
votes
0answers
173 views
Do serialization functions belong in a model or a controller?
I'm developing an application where:
Models keep data as a multi-dimensional array, which are saved as-is to a MongoDB database. The model is used to provide methods to manipulate the data, and ...
-2
votes
0answers
36 views
Get from object or use variable [closed]
Which one is better
//somewhere here i have Test test = new Test(); object
String name = "default";
if(test.getName() != null) name = test.getName();
or
String name = "default";
String ...
8
votes
6answers
867 views
Static functions vs classes
Let's say that I want to build some utility functions to do some basic maths with the BigDecimals, for example I want to have a function that computes the average of a List<BigDecimal>.
What is ...
6
votes
3answers
224 views
Implementing common logic in base class
Background
In the documentation of a project I'm working on I came across the following sentence which immediately triggered an alarm for me:
when having several concrete classes that inherits ...
0
votes
1answer
82 views
Multiple method calls in the constructor and dependency injection
I was asked to refactor some almost ureadable spaghetti code into object-oriented architecture.
I have some doubts regarding a class that I designed. Here is the class' skeleton:
require_once ...
0
votes
2answers
491 views
Object inheritance and method parameters/return types - Please check my logic
I'm preparing for a test and doing practice questions, this one in particular I am unsure I did correctly:
We are given a very simple UML diagram to demonstrate inheritance: I hope this is clear, it ...
1
vote
2answers
95 views
OOP (possibly Java-specific): Comprehensive Set of Method Categories [closed]
I am working on a coding convention to follow for my Java projects. I find it easier to find my way through a class when I group its methods by category. For example, rather than having each ...
1
vote
1answer
76 views
PHP OOP: value property is guaranteed different?
Imagine this code:
class Test
{
public $result;
public function makeSum($a,$b)
{
$sum = $a+$b;
$this->result = $sum;
}
}
In a webserver.
At same exact moment, ...
-2
votes
2answers
243 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 ...
9
votes
5answers
809 views
What is the meaning of “inversion” in Dependency Inversion design principle?
I'm reading about design patterns. I know what this principle does.
High-level and low-level classes depend on abstractions. But why we say this is inversion?
1
vote
1answer
61 views
Is it okay to expose implementation components in a library?
I'm writing a library for general consumption (It's free software and open source). Is it okay to have a visible namespace (e.g. Library.Implementation) for implementation-only components that remain ...
0
votes
1answer
112 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 ...
5
votes
7answers
1k views
OOP principles and method names
class Boxer:
def punch(self, punching_bag, strength):
punching_bag.punch(strength)
class PunchingBag:
def punch(self, strength):
print "Punching bag punched with strength", ...
-1
votes
3answers
106 views
Complex Number help
OK so I have a programming assignment and I need to create a class that represents Complex Numbers (good so far), add them to a list(good so far), and then output whether each individual number is ...
1
vote
5answers
239 views
Should abstract classes be used to prevent instantiation
Is preventing the instantiation of a class a valid reason to make it abstract? For example, if I have a class called Gauge which has subclasses HeadingIndicator and AirSpeedIndicator, is it a good ...
1
vote
5answers
339 views
Are there too many parameters in this constructor? [duplicate]
Check this out:
public function __construct(
\Magento\Framework\Model\Context $context,
\Magento\Framework\View\DesignInterface $design,
\Magento\Framework\Registry $registry,
...
2
votes
2answers
70 views
Optional Member Data
I am creating a strong binding of an XML specification and I am essentially trying to "flatten" the specification as much as possible, so that it won't feel like you are manipulating an XML tree.
...
0
votes
0answers
56 views
Ordering of methods in class [duplicate]
How do you order the methods in your classes?
I am aware of the alphabetical approach and the telling a story approach and so far I prefer the story approach, but how do you handle private/helper ...
5
votes
2answers
162 views
Sharing state with dependencies - Object-Oriented Design
Suppose that I define two interfaces below:
public interface IReader
{
void Read(string bookName);
}
public interface IWriter
{
void Write(string bookName);
}
Now I want to implement ...
14
votes
3answers
2k views
What is the reason of using an interface versus a generically constrained type
In object-oriented languages that support generic type parameters (also known as class templates, and parametric polymorphism, though of course each name carries different connotations), it is often ...
28
votes
2answers
2k views
Why is an anemic domain model considered bad in C#/OOP, but very important in F#/FP?
In a blog post on F# for fun and profit, it says:
In a functional design, it is very important to separate behavior from
data. The data types are simple and "dumb". And then separately, you
...
0
votes
1answer
156 views
Dealing with several custom getters
I have a data structure with data units containing different types of data. I've wrapped the data in "Field" objects so that each field is able to independently parse user input in a desired way.
...
0
votes
0answers
14 views
Extracting client specific code. refactoring possibilities required [duplicate]
I am facing a Design problem. I have a set of classes which writes data in XML,JSON or HTML formates for different clients.
I have a class which receives Data and a XML, JSON or HTML writer as it ...
1
vote
1answer
155 views
Is SICP still relevant? [closed]
Today, I came across this book entitled:The Structure and Interpretation of Computer Programs
I read the Table Of Contents and it really interests, me. It seems to be exactly what I've been looking ...
3
votes
1answer
138 views
Advantages and drawbacks of different ways using Either-types
I am writing software for compiling programs. Therefore have a Compiler that compiles a given sourcecode. It then returns a CompileResult that is similiar to an Either type (it is actually internally ...
0
votes
1answer
69 views
Are there any strong reasons to use DI for sub-classes that are known to be tightly coupled to their parent containers?
I have Product classes for Products A through Z. And each Product class has its own set of product-specific subclasses, which I'd say are tightly coupled to them, like so:
//specific product class ...
1
vote
1answer
151 views
Adding a graphical view to a system
I currently have an program in Java that simulates railway movements. Essentially, trains arrive on platforms, pick up and drop off passengers, and then proceed, respecting signalling where possible. ...
0
votes
2answers
107 views
Distinguishing Classes: How to catch system behavior in classes (Library System Case)
Suppose a Library System. if I think about Data, I can just distinguish Book, Member classes or at most Author or Publisher... (Are they only classes?), but I have some use cases, scenarios (Borrow, ...
0
votes
1answer
100 views
2 Classes that share similar behaviours but unrelated.
I'm working on something at the moment and am a little confused.
I'm working on an enquiry system in PHP (it's Opencart Based, so MVC).
An enquiry comes in and depending on what form it was ...
0
votes
2answers
372 views
Emulation of MMU accessing the contents of the registers
I'm having a play around with emulating a simple old CPU.
I've set the structure up, so far anyway, as follows:
The device is the main and creates an instance of the CPU. The CPU then creates ...
8
votes
7answers
1k views
what should be logger's position in the parameter list [closed]
In my code I inject a logger to many of my classes through their constructor's parameter list
I noticed that I put it randomly: sometimes it's the first on the list, sometimes last, and sometimes in ...
0
votes
5answers
293 views
Interview Question - Adding Method to interface that has been implemented by thousands of class [closed]
There is scenario where I have Interface X, which has been implemented with my thousands of classes. Now I want to add new method in that Interface X. So how to make the changes in minimal way to ...
1
vote
1answer
215 views
Building Data abstraction for rational numbers using “objects”
I follow this definition of "object":An object is a value exporting a procedural interface to data or behavior. Objects use procedural abstraction for information hiding, not type abstraction. Object ...
0
votes
3answers
813 views
Search and Replace in MVC
What would be a good MVC/OOP/GRASP/SOLID structure for a search/replace functionality. Methods: search/searchNext/replace/replaceAll.
I'm interested only in the PHP arhitecture and how a professional ...
3
votes
1answer
248 views
OOP - How to refactor a “pyramid architecture”
Unbeknownst to me while I was building it, I built a "pyramid" architecture. I did not realize this until I laid it out in my new Visual Studio 2013 Layer Diagrammer. Each layer depends on the layer ...
5
votes
5answers
307 views
Should the method describe its side effects? [duplicate]
I was reading Clean Code by Bob Martin and there's one particular code smell, related to naming, that looks interesting to me:
N7: Names Should Describe Side-Effects
Names should describe ...
1
vote
3answers
183 views
OOP implementation doubts with databases
I was starting a project today and after designing the database structure and how the data would be stored etc, I started the implementation. I am doing this on php, but the language isn't really ...