Effective Java, along with other sources suggest that we should consider using composition over inheritance. I have often found my self achieving such composition by using the Decorator pattern and implementing forwarding methods that delegate invocations to a wrapped object.
However, I often find myself writing many simple forwarding ...
Hi,
I am facing a class resolution issue while trying to make my architecture flexible. To make it simple, consider the following example:
I have four tiers: UI, BL, Common and DAL
I have a base class in my BL layer as defined below:
public class User
{
private UserDTO _d;
public User()
{
_d = ...
What is the best way to deal with "utility" functions in a OOP PHP framework? Right now, we just have a file with several functions that are needed throughout the system. (For example, a distribute() function which accepts a value and an array, and returns an array with the value distributed in the same proportions and same keys as the...
I'm wondering about the following issue: How deep should one go when designing an application in decomposing the working entities into objects?
What I mean could be described better by the following example.
Lets consider that I'm designing an application that is used to manage books.
For that the basic model would be the book. So at ...
Hi
I'm doing this:
@snippets = Snippet.find :all, :conditions => { :user_id => session[:user_id] }
@snippets.each do |snippet|
snippet.tags.each do |tag|
@tags.push tag
end
end
But if a snippets has the same tag two time, it'll push the object twice.
I want to do something like if @tags.in_object(tag)[...]
Would it be poss...
I may have made some poor design choices on this one. I have several objects being instanced like this.
core.modules.trial = function(sandbox){
return{
alert_private : function(){
alert(omgpi);
}
};
};
I would like to do this:
core.modules.trial[omgpi] = "external private var";
var trial = core.modules.trial...
sorry, just erased my code and did it again, it works now. must have been a silly mistake.
...
I have this code.
A base class that create a new instance of the context.
public class Base
{
private Entities context;
public Base()
{
context = new Entities();
}
}
And than the classes that inherit from this class.
public class SomeService : Base
{
public Gallery Get(int id)
{
...
Hi
I am creating an object structure and I want all sub classes of the base to be forced to implement a function.
The only ways I could think of doing it were:
An abstract class - Would work but the base class has some useful helper functions that get used by some of the sub classes.
An interface - If applied to just the base class t...
I really like the idea of reading others people code to improve your design skills. Open source can help here a lot.
This can teach you basic OO principles. But I'm not writing frameworks, I'm writing code for real customers with quite complicated domain logic.
There are lots of manuals of different MVC frameworks(like Create a blog wi...
This function in pkg go/token makes me wonder why we need a method that returns the receiver itself.
// Token source positions are represented by a Position value.
// A Position is valid if the line number is > 0.
//
type Position struct {
Filename string; // filename, if any
Offset int; // byte offset, starting at 0
L...
Hi all,
I am working on a project written in C++ which involves modification of existing code. The code uses object oriented principles(design patterns) heavily and also complicated stuff like smart pointers.
While trying to understand the code using gdb,I had to be very careful about the various polymorphic functions being called by the...
Say I have a swing GUI, and I want to listen MouseEvents. Who do you think should be the Listener class, who should be responsible? What is the best-or preferred way to implement it? Any opinions? I usually go like this:
public class MyPanel extends JPanel implements MouseListener{
private JTable table;
public void foo(){
...
Consider the following piece of code:
class B {
private:
// some data members
public:
friend bool operator==(const B&,const B&);
friend ostream& operator<<(ostream&,const B&);
// some other methods
};
template <typename T=B>
class A {
private:
// some data members
vector<vector<T> > vvlist;
public:
/...
Hi everyone,
I'm trying to clean up this ridonkulously ugly method here, that's crying out for refactoring, but I'm not sure what kind of structure would do this best (i.e. a case statement, or simply a carefully formatted if then statements)
At first glance, it looks like it would be an ideal place for a case statement with a few well...
So there are many ways of structuring objects (I'm talking of OOP here). For the question, I will use the classic "Car" example of OOP. Basically, How do I know when to make the car an object, or the wheel of a car an object, when both program structures would accomplish the goal?
How do I classify and categorize the parts of an object ...
I'm trying to write a somewhat generic method for retrieving data either from the browser cache if it's available, or a JSON request if it's not. Right now, all I want to do is be able to give my data.get method an id, and return the correct results. This works perfectly fine - console logs the new object being retrieved via JSON the fir...
I need to design a new API which models networked devices which have a large amount of attributes which vary quite a lot based on the device's type. The attribute set is not totally arbitrary though, it is a big set of known attributes. That said, with new devices come new attributes so the situation is never totally fixed.
The network...
Although the example below exploits ExtJS, one can easily extrapolate to another framework. I am a fan of abstraction and data hiding (and OO in general); does anyone else hide data and members/functions or do you consider this attempt to be overkill?
(Note: I believe strongly that DOM IDs should almost never be hardcoded. And, thou...
Is it possible to inherit a method within a class?
Or does it always need to be parent class inheriting child class?
For example:
A class called make_chart
Has:
public void style_Chart(Chart chartName,....)
{
}
Can I then inherit style_Chart into a new method called style_Chart2?
Something like this:
public void style_Chart2: ...