class Object
attr_reader :foo
def initialize
@foo = 'bar'
end
end
Object.new.foo # => 'bar'
''.foo # => nil
//.foo # => nil
[].foo # => nil
I want them all to return 'bar'
Am aware that you can do this already:
class Object
def foo
'bar'
end
end
But I specifically want to initialize a state variable. Also note th...
I have used OO programming languages and techniques years ago (primarily on C++) but in the intervening time haven't done much with OO.
I'm starting to make a small utility in C#. I could simply program it all without using good OO practice, but it would be a good refresher for me to apply OO techniques.
Like database normalization le...
Recently I was faced with this interview question (K-Means Clustering solution). The design I came up with did not meet the expectations of the interviewer (to put simply I didnt get the job because I lost to another candidate on this design problem). I am wondering how many different / efficient / simply solutions can the SO community c...
I am trying to figure out the best way to name my HTML form fields so that they can be easily parsed into a set of PHP opbjects.
For example I have the following table of elements: (let's assume it is inside a form)
<table>
<tr id='payment0'>
<td><input type='text' name='paymentType0'></td>
<td><input type='text' name='paymen...
In a pure programming context (such as structural & OOP), what are the main differences that you find (or must be careful not to be confuse) between Java/C++ and ActionScript? Any other notable or important differences are also welcome.
...
I'm basically wondering if Python has any OOP shortcomings like PHP does. PHP has been developing their OOP practices for the last few versions. It's getting better in PHP but it's still not perfect. I'm new to Python and I'm just wondering if Python's OOP support is better or just comparable.
If there are some issues in Python OOP wh...
Suppose Object1 needs information from Object2. I'll say it's in an Object2 property, but the info could as easily be the return value from an Object2 function. When I look at others' code I see sometimes they will have a method in Object1 directly accessing the property. Other times I see people pass Object2 as a parameter in a method, ...
Could someone please explain to me the differences between abstract classes, interfaces, and mixins? I've used each before in my code but I don't know the technical differences. (And yes, I've searched, but everything I found was either too technical or otherwise unhelpful.)
...
In the process of creating a module I am facing a dilemma: should each class internally define its own error codes, or should there be a module-wide error codes defined?
So far pros and cons go hand-in-hand, but I am inclined to define per-class errors:
1:
class MyClass
{
public:
typedef enum _TResult {
EOk = 0,
...
I have 2 tables in DB:
1- Element:
ElementID
ElementName
2- Methods:
MethodID
ElementID
MethodData
So there is a one to many relation between Elements and Methods,
I load these tables data using asp.net,
What i want to do is to send these data to my javascript, and javascript will do some functions on these data.
For example ...
I have a great manager who was a procedural coding wizard in his day. He is now faced with managing a team which uses object oriented programming in both .Net and Java. He struggles to understand a lot of the patterns and terminology we discuss. I am wondering what experiences SO members have had with helping others with this transition...
It seems that while I strive to maintain OO principles, it all seems so contrived or unnatural.
...
I've seen a million examples of DAOs, and for the most part they all implement your basic CRUD operations for single entities, with maybe a few methods that return lists (e.g. List getCustomers()).
However, I've never seen an example in which there is a method that updates, deletes, or creates multiple entities, like: void update(List)....
I'm somewhat new to OOP programming so it's very likely I'm making some stupid mistake. Here is my problem. When running my code I get the following error:
Fatal error: Call to a member function checkLogin() on a non-object in /application/libraries/Session.php on line 30
Below is the Session.php file (I've commented line 30 to mak...
Hey, I'm a fresh out of college graduate. I'm working on a project that I expect will be ultimately maintained by somebody else. I keep encountering an annoying situation on this project, and that is objects that require many private variables and as a result very long constructors.
Apart from variable naming, there isn't any coding sta...
If I create an object inside of the main scope:
INDEX.PHP:
$db = new database();
Then how can I use this same object inside of a completely different class?
ANYTHING.PHP:
class anything {
function __construct(){
$db->execute($something); # I want to use the same object from INDEX.PHP
}
}
Would I need to make $db a...
Feel free to point me to other answers if these have already been asked!
I'm just starting F# with the new release this month. I've got some background in both OO and functional languages (Haskell and Scheme, but not OCaml/ML). A couple of questions have arisen so far from reading through the little tutorial thing that comes with the F#...
I'm partial to using member initialization lists with my constructors... but I've long since forgotten the reasons behind this...
Do you use member initialization lists in your constructors? If so, why? If not, why not?
...
Which object oriented system in TCL is considered the standard?
...
Is it possible to create an object named after an NSString's value? If so, how?
...