A methodology that enables a system to be modeled as a set of objects that can be controlled and manipulated in a modular manner

learn more… | top users | synonyms (3)

67
votes
14answers
19k views

When are Getters and Setters Justified

Getters and setters are often criticized as being not proper OO. On the other hand most OO code I've seen has extensive getters and setters. When are getters and setters justified? Do you try to ...
71
votes
14answers
18k views

Where does this concept of “favor composition over inheritance” come from?

In the last few months, the mantra "favor composition over inheritance" seems to have sprung up out of nowhere and become almost some sort of meme within the programming community. And every time I ...
48
votes
2answers
4k views

Are there any OO-principles that are practically applicable for Javascript?

Javascript is a prototype-based object oriented language but can become class-based in a variety of ways, either by: Writing the functions to be used as classes by yourself Use a nifty class system ...
69
votes
5answers
9k views

Functional Programming vs. OOP

I've heard a lot of talk about using functional languages such as Haskell as of late. What are some of the big differences, pros and cons of functional programming vs. object-oriented programming?
25
votes
11answers
5k views

What is Object Oriented Programming ill-suited for?

In Martin Fowler's book Refactoring, Fowler speaks of how when developers learn something new, they don't consider when it's inappropriate for the job: Ten years ago it was like that with objects. ...
36
votes
9answers
4k views

Code Smell: Inheritance Abuse [duplicate]

It's been generally accepted in the OO community that one should "favor composition over inheritance". On the other hand, inheritance does provide both polymorphism and a straightforward, terse way of ...
92
votes
12answers
29k views

Why do we need private variables?

Why do we need private variables in classes? Every book on programming I've read says this is a private variable, this is how you define it but stops there. The wording of these explanations always ...
40
votes
12answers
13k views

What's the benefit of object-oriented programming over procedural programming?

I'm trying to understand the difference between procedural languages like C and object-oriented languages like C++. I've never used C++, but I've been discussing with my friends on how to ...
32
votes
6answers
2k views

How do I prove or disprove “god” objects are wrong?

Problem Summary: Long story short, I inherited a code base and a development team I am not allowed to replace and the use of God Objects is a big issue. Going forward, I want to have us re-factor ...
51
votes
15answers
15k views

What makes C so popular in the age of OOP?

I code a lot in both C and C++, but did not expect C to be the second most popular language, slightly behind Java. TIOBE Programming Community Index I'm curious as to why, in this age of OOP, C is ...
8
votes
4answers
435 views

Staying OO and Testable while working with a database

What are some OOP strategies for working with a database but keeping things unit testable? Say I have a User class and my production environment works against MySQL. I see a couple possible ...
43
votes
11answers
10k views

What is the ideal length of a method?

In object-oriented programming, there is no exact rule on the maximum length of a method , but I still found these two qutes somewhat contradicting each other, so I would like to hear what you think. ...
11
votes
4answers
1k views

How much design to do first? [duplicate]

I have never worked with a professional software development team. As such, analyzing and thinking about each and every aspect of my software does not come naturally to me. Whenever I strike an idea ...
12
votes
8answers
5k views

What is the point of an interface? [duplicate]

Possible Duplicate: When to use abstract classes instead of interfaces and extension methods in C#? What other reasons are there to write interfaces rather than abstract classes? This ...
13
votes
3answers
1k views

“Too object-oriented”

I come from a strong OO background, and I have recently started working in an organization which, although the code is written in Java, has a lot less emphasis on good OO design than what I am used ...
5
votes
1answer
585 views

Is wrapping a third party code the only solution to unit test its consumers?

I'm doing unit testing and in one of my classes I need to send a mail from one of the methods, so using constructor injection I inject an instance of Zend_Mail class which is in Zend framework. Now ...
31
votes
8answers
10k views

Is ORM an Anti-Pattern? [closed]

I had a very stimulating and interessting discussion with a colleague about ORM and its pros and cons. In my opinion, an ORM is useful only in the rarest cases. At least in my experience. But I don't ...
18
votes
4answers
4k views

Clarify the Open/Close Principle

As I have had it explained, the open/close principle states that once written code should not be modified (aside from bug fixes). But if my business rules change shouldn't I modify the code ...
21
votes
9answers
4k views

Should the methods of a class call its own getters and setters?

Where I work I see lots of classes that do things like this: public class ClassThatCallsItsOwnGettersAndSetters { private String field; public String getField() { return field; ...
5
votes
4answers
2k views

When or why should one use getters/setters for class properties instead of simply making them public properties?

I program primarily in ColdFusion but this is a general OOP question. Is there any benefit to using: getProp() { return prop; } setProp(val) { prop = val; } As opposed to simply obj = ...
98
votes
11answers
18k views

Should we avoid object creation in Java?

I was told by a colleague that in Java object creation is the most expensive operation you could perform. So I can only conclude to create as few objects as possible. This seems somewhat to defeat ...
45
votes
3answers
4k views

So what *did* Alan Kay really mean by the term “object-oriented”?

Reportedly, Alan Kay is the inventor of the term "object oriented". And he is often quoted as having said that what we call OO today is not what he meant. For example, I just found this on Google: ...
44
votes
17answers
4k views

Is OO-programming really as important as hiring companies place it?

I am just finishing my masters degree (in computing) and applying for jobs. I've noticed many companies specifically ask for an understanding of object orientation. Popular interview questions are ...
21
votes
5answers
2k views

How to make the transition to functional programming?

Lately, I have been very intrigued with F# which I have been working a bit with. Coming mostly from Java and C#, I like how concise and easily understandable it is. However, I believe that my ...
40
votes
20answers
7k views

Does Object Oriented Programming Really Model The Real World? [closed]

I've seen it commonly repeated the object oriented programming is based on modelling the real world, but is it? It seems to me that is not true of anything outside of the business layer. My GUI ...
18
votes
8answers
2k views

What can go wrong if the Liskov substitution principle is violated?

I was following this highly voted question on possible violation of Liskov Substitution principle. I know what the Liskov Substitution principle is, but what is still not clear in my mind is what ...
27
votes
6answers
3k views

Does learning a functional language make a better OOP programmer? [closed]

As a Java/C#/C++ programmer I hear a lot of talk about functional languages, but have never found a need to learn one. I've also heard that the higher level of thinking introduced in functional ...
7
votes
3answers
2k views

OOP oriented PHP app source code samples and advice

The day I have been dreading has arrived. I never felt OOP or good software design was important(I knew they were important, but I thought I could manage without them.). However having read otherwise ...
6
votes
4answers
606 views

Rails: Law of Demeter Confusion

I am reading a book called Rails AntiPatterns and they talk about using delegation to to avoid breaking the Law of Demeter. Here is their prime example: They believe that calling something like this ...
11
votes
1answer
603 views

How to verify the Liskov substitution principle in an inheritance hierarchy?

Inspired by this answer: Liskov Substitution Principle requires that Preconditions cannot be strengthened in a subtype. Postconditions cannot be weakened in a subtype. Invariants ...
5
votes
2answers
779 views

How does strengthening of pre conditions and weakening of post conditions violate Liskov Substitution principle?

I read that Liskov substitution principle is violated if : Pre conditions are strengthened . Post conditions are eased out. But I don't get fully yet how these two points would violate Liskov ...
35
votes
11answers
4k views

Are error variables an anti-pattern or good design?

In order to handle several possible errors that shouldn't halt execution, I have an error variable that clients can check and use to throw exceptions. Is this an Anti-Pattern? Is there a better way to ...
6
votes
3answers
2k views

When is method overloading appropriate?

Suppose I am working on an existing, reasonably large system. I have an object, myObject of class MyClass (for the example's sake, suppose I'm working in Java). myObject is a composition containing a ...
5
votes
4answers
28k views

What's the difference between overloading a method and overriding it in Java?

What's the difference between overloading a method and overriding it in Java? Is there a difference in method signature, access specifier, return type, etc.?
25
votes
13answers
5k views

Why are objects passed by reference?

A young co-worker who was studying OO has asked me why every object is passed by reference, which is the opposite of primitive types or structs. It is a common characteristic of languages such as Java ...
4
votes
4answers
825 views

Make methods that do not depend on instance fields, static?

Recently I started programming in Groovy for a integration testing framework, for a Java project. I use Intellij IDEA with Groovy plug-in and I am surprised to see as a warning for all the methods ...
3
votes
1answer
511 views

Composition vs. Inheritance [duplicate]

Here's what is given: public interface Request {} // there are 20 subclasses of Request public class CreateUserRequest implements Request { @NotEmpty public String userName; } // request ...
-1
votes
4answers
1k views

Is there really Object-relational impedance mismatch?

It is always stated that it is hard to store applications objects in relational databases - the object-relational impedance mismatch - and that is why Document databases are better. However, is there ...
81
votes
21answers
7k views

Is OOP hard because it is not natural?

One can often hear that OOP naturally corresponds to the way people think about the world. But I would strongly disagree with this statement: We (or at least I) conceptualize the world in terms of ...
54
votes
12answers
5k views

New to TDD. Should I avoid private methods now?

I'm just now learning TDD. It's my understanding that private methods are untestable and shouldn't be worried about because the public API will provide enough information for verifying an object's ...
36
votes
10answers
2k views

Clarify the Single Responsibility Principle

The Single Responsibility Principle states that a class should do one and only one thing. Some cases are pretty clear cut. Others, though, are difficult because what looks like "one thing" when ...
32
votes
4answers
4k views

What exactly is procedural programming? How exactly is it different from OOP? Is it the same as functional programming?

I am programming in Java in a very object-oriented (OO) style. OOP comes very intuitively to me, but I have very little knowledge about other kinds of programming. What exactly is procedural ...
124
votes
22answers
2k views

How do you educate your teammates without seeming condescending or superior?

I work with three other guys; I'll call them Adam, Brian, and Chris. Adam and Brian are bright guys. Give them a problem; they will figure out a way to solve it. When it comes to OOP, though, they ...
16
votes
11answers
2k views

What made object oriented programming successful? [closed]

What is that feature according to you that has made object oriented programming so much successful ? Message Passing Inheritance Polymorphism Encapsulation Or some other feature that you may like ...
35
votes
9answers
10k views

Can't I just use all static methods?

What's the difference between the two UpdateSubject methods below? I felt using static methods is better if you just want to operate on the entities. In which situations should I go with non-static ...
17
votes
5answers
3k views

Is objected oriented programming paradigm outdated since it is anti-modular and anti-parallel? [closed]

I have read the controversial article Teaching FP to freshmen posted by Robert Harper who is a professor in CMU. He claimed that CMU would no longer teach object oriented programming in the ...
30
votes
17answers
6k views

How can I feel more confident about my programming skills? [closed]

Programming isn't alien to me. I first starting doing markup (HTML, now please don't laugh at me) when I was 12 and a little bit of BASIC when I was 13 (I knew much about Flowcharts, Pseudocodes at ...
16
votes
11answers
3k views

is OOP the dominant programming model in real world?

Objects Never? Well, Hardly Ever In the VIEWPOINT section of Communications of The ACM, I found an interesting article entitled "Objects Never? Well, Hardly Ever". It’s a radically different ...
13
votes
1answer
3k views

What did they call Object-Oriented Programming before Alan Kay invented the term?

Alan Kay claims that "I made up the term "object-oriented", and I can tell you I did not have C++ in mind." What he had in mind, of course, was Smalltalk. But he did not make up object-oriented ...
25
votes
8answers
4k views

Why have private static methods?

I just wanted to clear up a question I have. What is the point of having a private static method as opposed to a normal method with private visibility? I would have thought an advantage to having a ...