Tagged Questions
1
vote
3answers
60 views
How to properly structure functions?
let's say we have a class with some methods in it, of which at least one is of rather complex nature:
class Example {
public function Example()
{
}
private function ...
4
votes
1answer
663 views
Overloading Getters In C++?
Good day,
I am unsure how to describe the process I am inquiring about properly in one sentence so please excuse the title. I was searching for a way to ensure that users of a base class and or ...
0
votes
2answers
63 views
What are some tips to make a function with a lot of calculation clean? [closed]
How can functions like this:
void Map::Display()
{
if(initialized)
{
HRESULT hr;
int hScrollPos = GetScrollPos(M_HWnd, SB_HORZ);
int vScrollPos = GetScrollPos(M_HWnd, ...
2
votes
3answers
58 views
How can I get data of different types from an anonymous class
I have an object that delegates some work to another object which is implementing an interface. Then, I am creating anonymous classes implementing this interface and I would like to get information ...
-3
votes
1answer
64 views
Which 'Design Pattern' is appropriate for a class with a complex (multiple steps) configuration [closed]
Whenever a setup-wizard is used, then the user answers many different things until the real installation can be started. Comparing this with a class in my current project: I have a class that requires ...
1
vote
2answers
40 views
Avoiding spaghetti code (gamestatemanager)
I am writing a StateManager for a game (I'm using C++ and SFML, but I tried to hide language specific elements because this is a question about any OOP language).
I have a setup in which a ...
2
votes
2answers
64 views
Using reflection in a factory
I have a factory which can build many types of object and it may grow.
Would it be a good idea to use reflection to return all the different types instead of calling every method in the ...
2
votes
1answer
67 views
Encapsulation: allow accessing of fields of any other than the current receiver object
Some object oriented languages (e.g. Smalltalk) do not allow accessing of
fields of any other than the current receiver object. For example:
expressions like this.good, or this.like:=false would be ...
2
votes
6answers
84 views
Is declaring a method static when possible good practice?
That's pretty self-explanatory. In Java, (and all OO languages I suppose) should I declare instance method when it's the only choice or generally we don't care about it?
6
votes
5answers
141 views
Should callers check validity of arguments before calling constructor?
I have been reading a lot about TDD and clean code recently so I start working on a simple project that puts these to use and I have come up against something that I am really not sure what the best ...
-3
votes
3answers
148 views
A general guideline approach to solving programming exercises? [closed]
Ok so there are a million questions on how to solve this and how to solve that problem, but I can't find a good resource on SO on how to actually go about solving programming problems in general. Like ...
2
votes
1answer
85 views
Writing jQuery-style function chains in AS3 and other class-based languages
This isn't a specific problem I have, more a choice I could make, but I do believe the question is relevant for SO as there may be a 'proper' OO answer, as well as a performance benefit/loss to doing ...
4
votes
4answers
143 views
Why does Google name accessors and mutators after member variables?
http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml?showone=Function_Names#Function_Names
Regular functions have mixed case; accessors and mutators match the
name of the variable: ...
0
votes
1answer
72 views
Pythonic approach to defining __init__ helper methods?
Please excuse me, I'm new to Python and trying to learn the Pythonic approach. I'm designing a class that essentially initializes its state from a number of different sources (files). I've isolated ...
1
vote
3answers
193 views
Scala immutable vs mutable. What is the way one should go?
I'm just learning to program in scala.
I have some experience in functional programming, as I have in object oriented programming.
My question is kind of simple, yet tricky:
Which structures should ...
0
votes
1answer
56 views
Abstraction of Model objects reasonable?
I'm currently working on a project where I'm adding a new rest interface.
I've written a generic converter which converts the response into some objects.
Now i'm asking myself if I should convert ...
3
votes
1answer
69 views
Should I use public setter to set private attribute value inside class?
Lets assume I have a class Test, which has got a private attribute called $_list, and a public setter.
Public setter is used to set the attribute value from the outside.
class Test {
private ...
2
votes
1answer
130 views
Correct way to prevent instantiation in Java [closed]
If we want to prevent instantiation of object in Java we can use several approaches and most obvious of them:
abstract keyword
private/protected constructor
Let's say class doesn't contain ...
1
vote
6answers
51 views
Placing methods to retrieve data related to a class in a separate class or not
Consider the following, simplified class:
class Book {
string title;
Author author;
}
Simple enough. However, when adding methods like getBookFromDatabase(int bookId), should this be placed ...
1
vote
2answers
123 views
JavaScript: Is it worth making variables private and defining getters/setters?
I'd like to start by saying that I understand that JavaScript is a Classless language. My background is in Java, C++, and Objective-C which are all classic OOP languages that support Classes.
I'm ...
-5
votes
5answers
361 views
What is the good programming practices in Java? [closed]
What is the good programming practices you think in Java?
The reson I ask this question:
I always wonder if I am doing in the wrong way so I want to know more about the good practices.
One thing I ...
-1
votes
3answers
114 views
Should I refactor a method that requires bool parameters [closed]
Any thoughts and/or opinions out there on using bool types as parameters into methods?
Some articles have expressed opinions that discourage the use of bool types as parameters to methods. Their case ...
6
votes
0answers
103 views
return on negative condition vs if block [closed]
If I have a function which should perform an action on some condition, and returns null instead, which is cleaner:
def func():
if not condition:
return None
[...]
return asd
or
...
4
votes
6answers
239 views
Is pointers to function as struct member useful in c?
I am not new to C programming. But I don't understand what is usefulness to keep pointer to function as a structure member in C. e.g.
// Fist Way: To keep pointer to funtion in struct
...
1
vote
4answers
283 views
Should a helper function go in the header or in the implementation file?
When writing a helper method for a class in C++, should it be declared as a private method in the class's definition in the header (.h) file? For example:
/*Foo.h*/
class Foo {
public:
...
1
vote
4answers
219 views
Syntax for Boolean getter/setter methods and properties
When writing Boolean getter/setter methods it seems standard to write them like so
void setValue(boolean value) { }
boolean getValue() { return true/false; }
However I have seen some usage which ...
2
votes
2answers
74 views
Should a class constructor return a subclass?
Should a class constructor return a subclass?
This is mostly a question about oop style and python style. I have problem where I need to implement a general case solution and, for performance ...
2
votes
2answers
190 views
Best way to design a class in python
So, this is more like a philosophical question for someone who is trying to understand classes.
Most of time, how i use class is actually a very bad way to use it. I think of a lot of functions and ...
-1
votes
3answers
72 views
Using tricks to enforce private inheritance in javascript
So I came up with something sort of hackish to check and see if a function is called from within the object itself. Can someone give me some good reasons not to do something like this?
function ...
0
votes
6answers
156 views
Basic questions on programming in .NET and managing projects [closed]
I am badly in need of some general advice / guidance. I am a C# programmer by interest, not by profession. As such, I have never worked on any project with other programmers.
Anytime I need to ...
3
votes
3answers
124 views
is it reasonable to use defmethod instead of defun even though there is no direct link between the class and the function/method
Consider this example:
There is a class named 'first', which is defined in package 'a'.
There is also a package 'b' which uses module 'a' functionalities.
Certain functions of package 'b' ...
0
votes
2answers
54 views
What prefix to use for methods that create or calculate a value
I wonder what prefix you guys use for methods that create or calculate a value based on given parameters. I tend to use "get", but that feels wrong, because it looks like a getter then.
For methods ...
2
votes
6answers
318 views
Return two values from a java method
Let's say I have a method in java, which looks up a user in a database and returns their address and the team they are on.
I want to return both values from the method, and don't want to split the ...
0
votes
0answers
68 views
oops design for multithreaded application with nunit test cases
I always wonder, what ever code I am writing, if some microsoft employee or google would be writing how they would have written that?
What level of OOPS modulation they would have done? Dividing ...
3
votes
1answer
132 views
How to handle n-m relationships with my PHP models?
I'm writing the specification for someone to create a model generator based on an existing database. I have created the below dummy database to illustrate the specification:
And here is a code ...
3
votes
1answer
104 views
What statups are expecting while asking to solve a programming challenge before hand? [closed]
I have applied to couple of startups and most of them are asking to solve programming challenge before they start on the interviewing candidate.
I have submitted couple of the solution and all the ...
2
votes
10answers
906 views
Why is programming to abstract classes instead of interfaces wrong?
I am going through the differences between Struts1 and Strust2 , i found out that ,
A common problem in Struts 1 is programming to abstract classes instead of interfaces.
Could anybody please let me ...
14
votes
6answers
495 views
Class linking best practices in C#
First off, EF is not an option for our development environment so please no "just use EF" answers ...
I think this is a pretty standard dilemma so I'm sure there must be a way that most Pros do it ...
12
votes
7answers
731 views
I have been writing PHP without “classes” for years… what am I missing?
For the life of me, I can't seem to wrap my head around "classes" in PHP.
I have managed to write large, scalable, and popular websites without them.
What am I missing? (And how do I learn?)
1
vote
3answers
185 views
Is it bad to prefix all of my framework class names?
I develop a lot of frameworks for Flash games and applications. I have always prefixed my class names with a random character or two, to avoid conflict with class names that the developer may already ...
1
vote
6answers
126 views
Advantage of using “this.”
I've read many large projects in OOP, and I notice that a lot of them use this.[variable], [ClassName].[staticVariable]. For example:
public class ABC {
private float mX;
public static float ...
6
votes
3answers
163 views
Is it good practice to use plurality to name collections? [closed]
Simply put, is it a good idea to name collections and composite objects using plurality?
class PandaBears {
PandaBear[] bears;
class PandaBear {
}
}
My concern is that the class names are ...
2
votes
1answer
64 views
Best way to use of setters in OOP
Let's assume I have a class and whenever I set certain attributes bla, foo (which can be set externally and internally) I want to call another method of the class, let's call it onChangeFunction().
...
1
vote
4answers
103 views
Python: How to handle method calls on a class that could not initialize correctly?
If an object relies on a module that is not included with Python (like win32api, gstreamer, gui toolkits, etc.), and a class/function/method from that module may fail, what should the object do?
...
1
vote
4answers
111 views
Calling function inside of function
When I code stuff, I try to divide all things in functions (methods, if you like). Function X does stuff X, Y does tuff Y and not like method X does stuff X, Y & Z! This gives me more re-usable ...
2
votes
3answers
1k views
Private vs Protected - Visibility Good-Practice Concern
I've been searching and I know the theoretic difference.
public - Any class/function may access the method/property.
protected - Only this class and any subclasses may access the method/property.
...
2
votes
8answers
842 views
Why encapsulate this field?
I've always been told to encapsulate ANY and ALL properties from a class...
This is right:
private string propertyName;
public string PropertyName
{
get { return propertyName; }
set { ...
2
votes
4answers
192 views
What is the best use of Inheritance other than reduce redundant code?
What is the best use of Inheritance, other than it will reduce redundant code!
Let us take an example
Class A:Base Class
Class B:Sub Class
and Class C.
CLASS A
^
| And ...
0
votes
2answers
171 views
Business Rule Violations and Exceptions
Can someone help me with a link to an article, or a link to a SO post that contains a link, on why its not a good idea to model business rule violations with exceptions. I'd also be happy with a ...
0
votes
3answers
129 views
Multiple instances v. single static instance
Let's say I have this custom component. It subclasses JMenuItem and all instances use the same Font object, although none share the same instance. For example,
public abstract class JFooMenuItem ...