A methodology that enables a system to be modeled as a set of objects that can be controlled and manipulated in a modular manner
-1
votes
0answers
30 views
PHP - Using $this when not in object context
When I try to execute this code from inherited class I got this error Using $this when not in object context
here my code
abstract class Connection {
private static $host;
private static ...
4
votes
7answers
992 views
Why is instance creation the way it is?
I've learned C# over the course of the past six months or so and am now delving into Java. My question is about instance creation (in either language, really) and it's more of: I wonder why they did ...
1
vote
0answers
40 views
Is this pattern of optional dependency injection sound?
A lot of the time when working on legacy code bases, I find it hard to move manually created dependencies to the constructor parameters, because of a variety of reasons. Sometimes it's because the ...
7
votes
8answers
1k views
Relation between object orientation and algorithms
As I read some algorithms textbooks, they are full of clever procedures for some problems (sorting, shortest path) or some general methods (recursive algorithms, divide and conquer, dynamic ...
5
votes
3answers
203 views
Is prototypal inheritance inherently slower?
I see Javascript 6 will add traditional class based inheritance, and one argument I hear is that classes are inherently much faster than prototypes because they can be optimized away by the compiler ...
0
votes
3answers
261 views
Overriding equals() method in Java
Short question: Why does Java allow overriding equals(), why is it not final?
I am reading Effective Java 2nd edition by Joshua Bloch.
I am a bit baffled by the conclusion that
There is no way to ...
0
votes
0answers
78 views
C++ as a first Language [on hold]
I recently signed up for a C++ course at my University with no prior programming knowledge. I realize, NOW anyways, that I should have taken a prior programming course, as I get lost in the concepts ...
0
votes
1answer
95 views
Change routing to comply with Law of Demeter
I have a Task, Owner and Plan. Charge values are kept in a plan, owner is on a particular plan and task knows its owner.
A task needs to setup its charges based on the knowledge the owner has. Owner ...
6
votes
2answers
274 views
What is the difference between Optionals and Nullable type
Swift has Optionals. C# has Nullable types.
As far as I can tell both serve same purpose, besides value of some type they store information whether variable has value or is undefined ...
1
vote
2answers
87 views
Controller in MVC
Alright so it is an essential part of OOP that one class should only do one thing, and it makes sense. In practice I've seen that classes which don't obey this rule get thick and cluttered.
So I was ...
19
votes
4answers
1k views
Why would many duck-typed dynamic programming languages use a class-based approach instead of prototype-based OOP?
Since quite many dynamic programming languages have the feature of duck typing, and they can also open up and modify class or instance methods at anytime (like Ruby and Python), then…
Question 1)
...
0
votes
1answer
80 views
Statistics about the usage of programming paradigms [closed]
I hear very often that the object-oriented programming paradigm is the most widespread. But are there any scientific statistics about how often other programming paradigms like procedural programming ...
0
votes
3answers
120 views
Should abstract classes be used to prevent instantiation
Is preventing the instantiation of a class a valid reason to make it abstract? For example, if I have a class called Gauge which has subclasses HeadingIndicator and AirSpeedIndicator, is it a good ...
3
votes
1answer
98 views
Creating variables in methods/functions
In how far do we create variables in our methods or functions?
Do we only create one when we're using the result of the variable more then one time like this?
function someFunction(SomeClass ...
1
vote
4answers
234 views
When is it not acceptable to model physical world objects with classes?
Does Object Oriented Programming Really Model The Real World? [closed]
also
"Firstly, A represents an object in the physical world, which is a strong argument for not splitting the class up." ...
1
vote
1answer
55 views
PHP MVC Display many records - model logic
I bet this question has been asked already but I can't form my thought as you can see from the title, so I couldn't find anything. I am working with MVC for quite some time now and I'm pretty happy to ...
2
votes
1answer
83 views
Proper way to refactor multiple if based conditions [duplicate]
I took over a large legacy code base. It has a code like this:
if ($route == 'login' || $route == 'logout' || $route == 'forgot-password') {
return;
}
if ($loggedInUser == false && ...
-1
votes
0answers
51 views
Is partial application of functions the corresponding technique for state saving objects?
Imagine we have Converter object which is responsible for converting Strings in different ways, e.g. with convertingMethod1 and convertingMethod2. As the Converter depends on some context, it also ...
15
votes
6answers
914 views
Does functional programming increase the 'representational gap' between problems and solutions? [closed]
Since machine language (e.g., 0110101000110101) computer languages have generally evolved to higher forms of abstraction, generally making it easier to understand the code when it's applied to a ...
2
votes
1answer
186 views
Why do mainstream OO languages not have immutability on class-level built-in? [duplicate]
I regularly write classes which can only have immutable instances, much like string.
I am wondering why Java or C# or VB.NET don't have immutability built-in into the language? That way, I can ...
0
votes
1answer
64 views
Condition before statement or statement in condition
I've come across this problem a few times:
Is there any "programming rule" for checking for an condition (error checking for example) before you want to do execute code, or only execute the code when ...
0
votes
3answers
77 views
Heuristics on when should one subclass and when not [closed]
Are there any good tips, when one should subclass and when should not?
It's clear that we should not subclass when
we want to reuse a single method of some class
we override all methods, changing ...
5
votes
1answer
111 views
How to use OO Design to Refactor a Library with Functions that are specific Product-aware
I have a class that acts as a library of functions for various products. To compute its data, the function currently needs to be aware of all product names. Depending on which product calls the ...
-1
votes
1answer
96 views
Why is it said that a class represents an abstraction? [closed]
I think that abstraction represents only the essential things needed for the purpose as there are so many unnecessary properties. So why is it said that a class represents an abstraction?
8
votes
5answers
2k views
class in OOP language and type
In programming language theory, a type is a set of values. E.g. the type "int" is the set of all integer values.
In OOP languages, a class is a type, is it?
When a class is defined with more than ...
2
votes
2answers
105 views
Initialize physical resources in constructor
Is it an acceptable practice to initialize physical/external resources from a constructor when the resource is needed for the object to do it's work?
For instance, let's say I wanted to create an ...
-4
votes
1answer
151 views
object oriented programming vs. object oriented design [closed]
We know what is object oriented programming but my question is:
What is the difference between object oriented programming and object oriented design?
4
votes
4answers
306 views
Does Object Orientation require the concept of inheritance? [closed]
I read Object-Oriented Analysis and Design with Applications Notes written by Grady Booch. In the book there is a sentence:
There are three important parts to this definition: (1) Object-oriented ...
2
votes
2answers
121 views
Can a class method be accessed both in an instance and statically?
I am relatively new to class design and I have a task that I'm not sure how best to complete, or whether my idea in general is a code smell.
I'm developing a RPG where people can own monsters, so ...
0
votes
4answers
220 views
How should nodes in a chain be connected?
Suppose you were building a system that receives data on one end and sends filtered data on the other end.
The system is a chain of nodes, each receiving data from the node before and sending ...
1
vote
4answers
154 views
What is the efficient way to eliminate duplication? Design patterns?
I have a helper class which has a method that perform some checks against a field in a model. I have two models, ModelA and ModelB, they have some similarities but not all. One of them is they both ...
0
votes
1answer
160 views
Interface or boolean?
I have a CustomObject class which has the abilities like being Clickable, KeyPressable and Movable. I created interfaces: IClickable, IKeyPressable and IMovable and make different CustomObject classes ...
1
vote
2answers
72 views
Parsing input into multiple subclasses
Lets say I have 10 xml message types that come into my program via some type of input (file, port, etc). I have 10 subclasses of a type Message to handle the unique needs of each message type.
When a ...
2
votes
3answers
153 views
Good or bad idea to create a “fromJSON” static factory constructor for an object that is often created by parsing a JSON coming from API?
I have a "Product" POJO class in my app.
A Product object can either be created in-app by the user or by parsing a json that comes from the API.
Product has 20+ fields, but Im using only 2 here for ...
1
vote
1answer
103 views
Adding a graphical view to a system
I currently have an program in Java that simulates railway movements. Essentially, trains arrive on platforms, pick up and drop off passengers, and then proceed, respecting signalling where possible. ...
1
vote
0answers
128 views
How to separate out below tightly coupled classes
I have two classes which are somewhat tightly coupled to one another. Lets call them A and B. A derives from C and B derives from D.
B is the class whose instance is created by the system and then B ...
1
vote
1answer
33 views
Splitting single Class into multiple Classes
I am writing automated test scripts with Selenium Webdriver (Python) and I try to follow the correct programming practices, specifically the Object Oriented methodologies, where possible.
At the ...
2
votes
1answer
63 views
Combining Patterns: Fluent Builder and Null Object Pattern
I am currently wrestling around with some GUI code where I have a table whose rows correspond to some object, let's say a Person object. When the table initializes, it fills the table with the Person ...
1
vote
1answer
133 views
How to represent “class” data type in C or any low level language? [closed]
I'm writing a simple language compiler,currently it's support functional programming only.
I want to support OOP concept, but I don't know how exactly I can represent an object ? just where to start ...
0
votes
2answers
201 views
What's the benefit of having everything as an object in dynamically typed programming language? [closed]
modern dynamic programming languages like Python, Ruby and Javascript all take the approach of treating everything as an object, what's the benefit of this approach, and what's the curse of it?
...
3
votes
1answer
108 views
Unit testing a template class after refactoring
I am cleaning up my code by way of removing duplicates, and found two classes that were almost identical, out of 55 lines, only a single predicate in an if statement differed between them.
Both ...
1
vote
1answer
102 views
Where to put data for tree structure which every node requires?
I have a quad-tree structure where each node has some of its own data, but there is also data which applies to the tree as a whole.
I'll explain my current solution and I would appreciate feedback on ...
-1
votes
2answers
94 views
In plain English, what is an object model? [closed]
I read about objects models on Wikipedia, but it is too abstract to really make much sense to me. Can someone explain what an object model is in plain English?
2
votes
1answer
153 views
Why do class-based OO-languages always use the keyword `new` to create an object? [duplicate]
I do not know much about OO-languages, but from what I have seen, it seems most class-based OO-languages uses a keyword new (or something equivalent) to create an object. Prototype-based OO-languages ...
1
vote
3answers
143 views
Does overriding a method affect a superclass's call?
I'm trying to understand some of the nuances of inheritance but I can't find an answer to this question. Consider the following:
class SuperClass {
method foo {
print "in SuperClass.foo"
...
25
votes
7answers
2k views
What are the caveats of implementing fundamental types (like int) as classes?
When designing and implenting an object-oriented programming language, at some point one must make a choice about implementing fundamental types (like int, float, double or equivalents) as classes or ...
2
votes
4answers
239 views
Two classes that behave identically yet are semantically different
I am writing a program which is a similar to Ruby's Active Record Migrations, in which that every migration has both an "Up" and "Down" in terms of creating a change to the database, "Up" meaning ...
3
votes
3answers
148 views
What is the correct Object Design/Architecture for the following scenario?
I am developing some custom controls in an Object Oriented language (using Swift/Cocoa but this is a technology agnostic question). In particular, I have a horizontal and vertical set of buttons that ...
0
votes
3answers
60 views
Event Driven Objects/Framework on the Web [closed]
I am a desktop developer moving to web development. The guys who I am working with use procedural PHP, and coming from an event driven, objectified perspective (using WPF and C#.Net) I am completely ...
1
vote
2answers
85 views
How do you decide member objects?
So OOP is about breaking down functionality, making each class responsible for one thing etc. But let's take the example where an object is using another object. First thing that comes to mind ...