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)

126
votes
23answers
34k views

If immutable objects are good, why do people keep creating mutable objects?

If immutable objects¹ are good, simple and offer benefits in concurrent programming why do programmers keep creating mutable objects²? I have four years of experience in Java programming and as I see ...
125
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 ...
99
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 ...
93
votes
12answers
30k 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 ...
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 ...
79
votes
18answers
7k views

Is it poor programming practice to pass parameters as Objects? [duplicate]

So, we've got a guy who likes to write methods that take Objects as parameters, so they can be 'very flexible.' Then, internally, he either does direct casting, reflection or method overloading to ...
72
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 ...
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?
68
votes
14answers
20k 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 ...
64
votes
14answers
4k views

Name for this antipattern? Fields as local variables

In some code I'm reviewing, I'm seeing stuff that's the moral equivalent of the following: public class Foo { private Bar bar; public MethodA() { bar = new Bar(); ...
64
votes
16answers
11k views

Do I really need oop for my kind of job? After 10 years I think I don't [closed]

After 10 years of writing something like business logic for my company I realized that for 95% of my code I just don't need any special OO techniques. For years I tried to get better with all that OO ...
59
votes
21answers
10k views

Why is OOP difficult?

When I started using an object-oriented language (Java), I pretty much just went "Cool" and started coding. I've never really thought about it until only recently after having read lots of questions ...
59
votes
10answers
5k views

Zero behavior objects in OOP - my design dilemma

The basic idea behind OOP is that data and behavior (upon that data) are inseparable and they are coupled by the idea of an object of a class. Object have data and methods that work with that (and ...
59
votes
1answer
10k views

Should package names be singular or plural?

Often, in libraries especially, packages contains classes that are organized around a single concept. Examples: xml, sql, user, config, db. I think we all feel pretty naturally that these packages ...
58
votes
7answers
37k views

Aggregation vs Composition

I understand what composition is in OOP ,but I am not able to get a clear idea of what Aggregation is . Can someone explain ?
56
votes
11answers
8k views

Why is C not considered an 'object-oriented' language?

It seems that C has its own quasi-objects such as 'structs' that can be considered as objects (in the high-level way that we would normally think). And also, C files themselves are basically separate ...
56
votes
16answers
19k views

Is it better to return NULL or empty values from functions/methods where the return value is not present?

I am looking for a recommendation here. I am struggling with whether it is better to return NULL or an empty value from a method when the return value is not present or cannot be determined. Take ...
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 ...
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 ...
51
votes
6answers
4k views

What really is the “business logic”?

I'm working with web development since 2009, when I started with PHP. When I moved to ASP.NET I've heard a lot about DDD and OOAD where a lot of focus is given to this "business logic" and "business ...
49
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 ...
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 ...
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. ...
41
votes
11answers
8k views

Why is it good to split a program into multiple classes?

I'm still a student in high school (entering 10th grade), and I have yet to take an actual computer course in school. Everything I've done so far is through books. Those books have taught me concepts ...
40
votes
8answers
3k views

Do object-oriented programming languages exist that are not class-based?

Are there any object-oriented programming languages that are not based on the class paradigm?
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 ...
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 ...
38
votes
1answer
2k views

Why do programmers use `Acme` as a package, namespace or directory name

This may or may not be a silly question, but I really would like to know the answer to something which has been bothering me for a while. I quite often see programming examples/conventions where the ...
38
votes
7answers
2k views

How can I get my progress reviewed as a solo junior developer

I am currently working for a 2 person company, as the solo primary developer. My boss gets the clients, mocks up some png design templates and hands them over to me. This system has been working fine ...
37
votes
9answers
4k views

Do we need Logging when doing TDD?

When doing the Red, Green & Refactor cycle we should always write the minimum code to pass the test. This is the way I have been taught about TDD and the way almost all books describe the process. ...
37
votes
12answers
2k views

Documentation in OOP should avoid specifying whether or not a “getter” performs any computation?

My school's CS program avoids any mention of object oriented programming, so I've been doing some reading on my own to supplement it -- specifically, Object Oriented Software Construction by Bertrand ...
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 ...
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 ...
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 ...
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 ...
34
votes
14answers
11k views

Isn't MVC anti OOP?

The main idea behind OOP is to unify data and behavior in a single entity - the object. In procedural programming there is data and separately algorithms modifying the data. In the ...
34
votes
8answers
4k views

What should be allowed inside getters and setters?

I got into an interesting internet argument about getter and setter methods and encapsulation. Someone said that all they should do is an assignment (setters) or a variable access (getters) to keep ...
33
votes
1answer
952 views

What's a generic word for both Methods and Attributes?

In a class diagram, each class contains methods and attributes. What's the correct word for describing both of them besides something generic such as contents or items? Context: The Orange class ...
33
votes
3answers
1k views

Does Java development typically involve more subclassing than C#/.NET?

I've recently started looking at Android development. This has brought me back into the world of Java software development. The last time I worked with Java, I'll admit, I didn't understand OOP nearly ...
32
votes
18answers
7k views

Does OOP fulfill the promise of code reuse? What alternatives are there to achieve code reuse?

Perhaps the greatest promise of using object-oriented paradigm is the code reuse. Some dispute that this was achieved. Why was it (not) achieved? Does code reuse as OOP defines it, make projects more ...
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 ...
32
votes
6answers
2k views

Why is “tight coupling between functions and data” bad?

I found this quote in "The Joy of Clojure" on p. 32, but someone said the same thing to me over dinner last week and I've heard it other places as well: [A] downside to object-oriented programming ...
32
votes
6answers
3k 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 ...
31
votes
18answers
6k views

What would you do if your client required you not to use object-oriented programming?

I am writing a program to simulate the activity of ants in a grid (PDF). The ant can move around, pick up things and drop things. The problem is while the action of the ants and the positions of each ...
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 ...
30
votes
17answers
7k 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 ...
30
votes
2answers
1k views

What did Alan Kay mean by “assignment” in The Early History of Smalltalk?

I have been reading The Early History of Smalltalk and there are a few mentions of "assignment" which make me question my understanding of its meaning: Though OOP came from many motivations, two ...
29
votes
12answers
8k views

Why does PHP have interfaces?

I noticed that as of PHP5, interfaces have been added to the language. However, since PHP is so loosely typed, it seems that most of the benefits of using interfaces is lost. Why is this included in ...
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 ...