Organize methods by type of return or argument?

I'm having a bit of a hard time articulating this problem. With different types, what considerations are there for how to organize methods that traverse the relationships to convert to a different type? While being forgiving about the precise modelli

JS self-refreshing app / disappearing item EDITED

EDITED Managed to get most of it working, but have a problem towards the end. I have an html file with a few input fields and div elements to which I have to append a recipe when it is created. So I have two classes separated in modules - recipe and

How to define an immutable object in a mutable Java class?

In a class, I want to define an empty object and use it anywhere we need it. This object needs to be immutable to avoid accidentally modification. If this object is defined as a public static final member of the class, the object could be changed if

Private methods or internal class

I am working on a class which needs couple of helper methods. This methods are going to be used only by this class. So I am wondering which will be best practice i.e. whether declaring these helper methods as private methods or group them and put ins

test python compares 2 objects of the same class

In a test, I need to compare that 2 objects of a class have the same values for each of the class attributes. I do not need to compare 2 objects of the class outside of my testing. Is it better to implement the eq in my class (even though the product

Base class C # has a derived class member and loop

I have this class: public class GameData { public int[,] mat { get; set; } public int dim { get; set; } public int goal { get; set; } public Game game { get; set; } public GameData() { game = new Game(); } } And this two other derived classes: public

Why does the java method not support multiple return values?

This question already has an answer here: Return multiple values from a Java method: why no n-tuple objects? 6 answers While working with Java Applications, I feel most of the times one question : Why Java doesn't support multiple return values of me

Recursive summary ToString () in base class?

Look at the following (pseudo) pattern: public abstract class Animal { public abstract AnimalType { get; } public abstract override string ToString() { return String.Format("{0}={1}", AnimalType, this.ToString()); ^ // does this even work? } } w

How (which design model) to manage the addition of new fields?

I have been doing web app for medical data collection for a long time. Clients always have this kind of request : adding a new field in the form, for example they want add "gender" in demographic form. Every time they request, I have to 1. Add a

Difference between constant declared in interface and class?

I ran into a peculiar issue I was curious about (and would like to find a workaround for). If I declare a variable NODES in my class: private static final String NODES = "nodes"; Everything works ok. However, if I declare the variable in an inte

How can I serialize an interface?

Suppose I have a Serializable class ShapeHolder that owns an object that implements a Serializable Shape interface. I want to make sure the correct concrete shape object is saved (and the correct type is later restored). How can I accomplish this? in

How to connect to MongoDB from another PHP class?

I have the following code to connect to MongoDB: try { $m = new Mongo('mongodb://'.$MONGO['servers'][$i]['mongo_host'].':'.$MONGO['servers'][$i]['mongo_port']); } catch (MongoConnectionException $e) { die('Failed to connect to MongoDB '.$e->getMessag

What is the best data structure to use for type query?

I am in the process of making a game, and in that process I have come across a bit of a problem. I have many different types of game elements. These are all of type Entity. There are many types of Entities, including ones that are visible and need to

PHP - Object Mixing Injection & amp; heritage

This is a follow up question on the following answer : Parent Object in php class A { protected function doSomeStuff(){ echo 'a method that all children will need to call'; } } class B { protected $_parent; public function __construct($parent) { $thi

Java ArrayIndexOutOfBoundsException in Tic-Tac-Toe

This question already has an answer here: How to avoid ArrayIndexOutOfBoundsException or IndexOutOfBoundsException? [duplicate] 2 answers I'm making a simple Tic-Tac-Toe program but I'm getting java.lang.ArrayIndexOutOfBoundsException if my input goe

PHP OOP: How to use a generic MySQL class in other classes

I've just started using OOP PHP and ran into a question. I've set up a generic mysql class that allows me to connect to a database and has some functions to obtain records from a table: class mysql{ //some lines to connect, followed by: public functi