Questions tagged [object]

95 questions
85
votes
14 answers

Do objects in OOP have to represent an entity?

Does an object have to represent an entity? By an entity I mean something like a Product, Motor, a ParkingLot etc, a physical, or even a clear-cut non-physical conceptual object -- something that is well defined, with some core data clearly…
Dennis
  • 8,157
  • 5
  • 36
  • 68
59
votes
8 answers

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 things but I am getting push-back from the teams who…
honestduane
  • 715
  • 1
  • 6
  • 5
31
votes
6 answers

Can you implement "object-oriented" programming without the class keyword?

Say we want to provide an abstraction of an "account" in a bank. Here's one approach, using a function object in Python: def account(): """Return a dispatch dictionary representing a bank account. >>> a = account() >>>…
overexchange
  • 2,245
  • 2
  • 17
  • 47
22
votes
4 answers

What are the differences between class variables and instance variables in Java?

I'm very new to Java and want to understand the difference between class variables and instance variables. For example: class Bicycle { static int cadence = 0; int speed = 0; int gear = 1; } How are instance variables and class…
Skylar Adams
  • 433
  • 2
  • 4
  • 6
22
votes
11 answers

When would you want two references to the same object?

In Java specifically, but likely in other languages as well: when would it be useful to have two references to the same object? Example: Dog a = new Dog(); Dob b = a; Is there a situation where this would be useful? Why would this be a preferred…
Bassinator
  • 714
  • 1
  • 8
  • 22
21
votes
1 answer

Design pattern for object conversion (java)

I don't use design patterns very often, besides an occasional factory and MVC, and I want to start using them more. I have a concrete case at hand that I would like your opinion on the use of design patterns in this case. In my application I have to…
Julius
  • 568
  • 1
  • 3
  • 7
18
votes
4 answers

Unable to solve mystery of functions in Javascript

I am trying to understand behind the curtain scenes of Javascript and kind of stuck in understanding the creation of built in objects, specially Object and Function and the relation between them. When I read that all the built in objects like Array,…
Umair Abid
  • 890
  • 2
  • 8
  • 15
18
votes
5 answers

Why am I seeing so many instantiable classes without state?

I'm seeing a lot of instantiable classes in the C++ and Java world that don't have any state. I really can't figure out why people do that, they could just use a namespace with free functions in C++, or a class with a private constructor and only…
futlib
  • 2,107
  • 3
  • 21
  • 26
17
votes
3 answers

How many strings are created in memory when concatenating strings in Java?

I was asked about immutable strings in Java. I was tasked with writing a function that concatenated a number of "a"s to a string. What I wrote: public String foo(int n) { String s = ""; for (int i = 0; i < n; i++) { s = s + "a" …
ahalbert
  • 333
  • 1
  • 2
  • 8
12
votes
5 answers

Config Class/Struct: Pattern or Anti-Pattern? Alternatives?

If you add new configuration options to a program, it can often have tons of ripple effects in terms of getting the options to where they need to be acted upon. There are three basic ways to deal with this that I'm aware of: Pass all configuration…
dsimcha
  • 17,224
  • 9
  • 64
  • 81
10
votes
1 answer

Object Constraint Language (OCL) for Stack in java.util package

I have an exam coming up and I'm looking at past papers to get some ideas of what to expect. I'm a bit stuck on the following one and would really appreciate if someone could give some example answers. Write preconditions and postconditions in OCL…
Aimee Jones
  • 201
  • 2
  • 8
8
votes
3 answers

Is a single object to be preferred over multiple variables?

It was quite hard to put what I meant into a title, but it's easy to put into code. C++ Is this int offset_x = 10; int offset_y = 40; ... element.move(offset_x, offset_y); To be preferred over this? Vector offset(10,…
futlib
  • 2,107
  • 3
  • 21
  • 26
7
votes
6 answers

Is it called class or object instance?

I have a wording / precision question. Sometimes I write "object instance" sometimes "class instance". Isn't it that an object is always an instance of a class? Therefore "object instance" is not the correct wording, right? Is it common to say so…
hakre
  • 1,165
  • 12
  • 17
7
votes
4 answers

When in your language classes are objects too, does the Liskov substitution principle apply to their interfaces?

According to Wikipedia the Liskov substitution principle states that objects in a program should be replaceable with instances of their subtypes without altering the correctness of that program Normally the Liskov substitution principle doesn't…
aef
  • 321
  • 1
  • 7
7
votes
2 answers

Is there a standard, formal name for an object or class that behaves as if it is a given object?

I have an app in Django that expects to get a record with the fields email, first_name, and last_name. However, sometimes I want to be able to send it something that isn't actually a record but behaves like one (in that it has the necessary fields…
Jordan Reiter
  • 623
  • 5
  • 13
1
2 3 4 5 6 7