I have multiple classes (controllers) that share a huge chunk of code with each other. How can I factor out this piece of code? The code is some methods that belong to a protocol. In other words, all my controllers are behaving the same way with regards to this protocol. I can't make them subclasses of the same parent because they are al...
I have been programming in object-oriented languages for years now but secretly I look at some of the things my colleagues do with envy. A lot of them seem to have some inner OO instinct that I don't have - no matter how hard I try. I've read all the good books on OO but still can't seem to crack it. I feel like the guy who gave 110% ...
I have a search class that I am using to fetch results from two different sources and combine them together. The Search class is the parent and has two children A and B which extend Search.
In the Search class, I have a method called fetch() which instantiates the two child objects to get their results. It looks something like this:
...
So I have:
class foo {
public $variable_one;
public $variable_two;
function_A(){
// Do something
$variable_one;
$variable_two;
// If I define variable_3 here!
$variable_3
// Would I be able to access it in function_B?
}
function_B(){
// Do something
$variable_4 = $variable_3
}
}
$myObj = ...
I received the following email today from a co-worker. My question is this accurate. Nesting Business Objects is bad practice? Can anyone shine in on this?
Nested Objects
When any variable is created within C# it takes up a piece of memory on the Web Server. Since we will have many tools running on the same server, it is even more impor...
class XFactory {
private XFactory() {}
static void getX() {
if(...)
return new A(new XFactory());
else
return new B(new XFactory());
}
}
class A {
private A() {}
public A(XFactory xf) {}
}
class B {
private B() {}
public A(XFactory xf) {}
}
By this way I can ensure only Factory can create inst...
So, I've noticed that I definitely have a tendency to pattern my Spring/Hibernate stack objects like this:
Foo controller makes a call to "FooService"
FooService calls FooRepository.getById() method to get some Foos.
FooRepository makes some Hibernate calls to load Foo objects.
FooService does some interactions with the Foos. It may us...
I am trying to make a function f that works like this:
StorageObject::addItem (const AbstractBase& base) {
AbstractBase* storage = new Derived1(base);
}
However, I would like f to work with classes Derived2, Derived3 etc as well. Is there a way to get f to call the correct constructor depending on the specific subclass of Abstract...
As an OO developer, maybe I have difficulty seeing its value. What added value do they give? Do they fit in an OO world?
...
OOP is about programming with interface, not the implementation. Objects are "talking" to each other using their interfaces. When interfaces are not well defined one object can know too much about the other and if you need to change implementation of your object you'll need to change your programm in different places. That's really bad, ...
Jquery has utility a function called 'extend' which can be used to merge objects. It is very useful to merge default options with the user specified options , to get the effective options.
Is there any similar function in c#/.Net ?
class settings
{
public string Directory;
public string Username;
}
settings default_set = new ...
Consider the following PHP snippet:
<?php
class Is
{
function __get($key)
{
$class = __CLASS__ . '_' . $key;
if (class_exists($class) === true)
{
return $this->$key = new $class();
}
return false;
}
function Domain($string)
{
if (preg_match('~^[0-9a-z\-]{1,63}\.[a-z]{2,6}$~i', ...
Hello.
I'm developing a little site using ASP.NET MVC, MySQL and NHibernate.
I have a Contact class:
[ModelBinder(typeof(CondicaoBinder))]
public class Contact {
public virtual int Id { get; set; }
public virtual string Name { get; set; }
public virtual int Age { get; set; }
}
And a Model Binder:
public class Contac...
Many people know this article: more on getters and setters. I think it does a convincing job of portraying the evil side of getters/setters. I've also tested it by trying to convert an existing project (unfinished) to code without getters/setters. It worked. Code readability improved greatly, less code and I've even managed to get rid of...
Hey,
This is my first foray into OO JS, having issues.
Ideally in this scenario, I'd have a mapLocation object, which i could just pass in coordinates, icon, the HTML to display upon click and that's it. I'd add it to my Google map on the page and I'd have something somewhat re-usable. Obviously this would be refactored later.
Also,...
Imagine that I have a nice Deck class, in the best OO fashion. It has Cards, which have a Suit and a Rank, it has a Shuffle method, and so on. Now, I'm going to have a lot of concurrent instances of Deck (say this is a casino). The question is: Should there be a different instance of every card across all the decks?
...
Hi all,
When implementing a class, is it better practice to return a value for methods (interrogative) or to simply manipulate class attributes directly within the method (imperative).
For example, I have a class which builds a string to be output to a CSV file. I might do it this way:
String output = ""
String records[] = //list of ...
I've got the code below, and I was planning on making several classes all within the same "import". I was hoping to instantiate each class and get a return value with the widgets I'm making.
This isn't really a PyQt question at all, more of a "good practices" question, as I'll have a class for each widget.
Should I make functions th...
I've been searching the web for some time now. I am looking for small sample exercises for OOD practice (& for some internal TDD workshops).
If there is one single place, where this need is being served, please point me to it.. and close this question
Constraints:
Language-agnostic real world problem
Small : Something that takes an ho...
Greetings fellow overflowers,
After reading on MSDN about correct strategies on how to perform database replication, and understanding their suggestion on Master-Subordinate Incremental Replication. It left me wondering, what OOD design pattern should I use on this...
The main elements of this strategy are the Acquirer, the Manipulator...