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)

5
votes
8answers
569 views

When do we actually use object-oriented programming?

I am writing a program in Python, which basically manipulates strings, and I was wondering whether I should do it using OOP principles or not. The client did tell me he doesn't care about the code, he ...
0
votes
3answers
190 views

When NOT to use a class / member variable?

I am trying to learn WHEN NOT to use: classes member variables HERE IS THE CODE access_point_detection_classes.py from scapy.all import * class Handler : def __init__(self) : ...
0
votes
2answers
44 views

Object Oriented Python methods and their parameters

Let's say I have a class MyClass ... which has a data member x class MyClass1 : def __init__(self) : self.x = 1 Also a method which does something with x Should I pass self.x as a ...
-3
votes
0answers
39 views

Explanation of DRY with regards to OOP needed [on hold]

An online test I was doing had this question re DRY with regards to OOP. I must confess that even though I thought I understood both, it has me stumped. Any ideas?
-4
votes
0answers
22 views

Objects and Classes in Python [on hold]

Can anyone: 1. Define what an object is in programming and python. 2. What is class in programming 3. Give an example of an object in python 4. Give an example of class in python I can't seem to ...
2
votes
2answers
112 views

Nested functions: should I explicitly pass arguments or rely on scope?

Suppose I have a function f that uses two helper functions h and g to get the job done. There are two possible ways of dealing with this situation. (1) take explicit arguments and returns new objects ...
0
votes
3answers
233 views

Is it bad practice to ignore some parameters while implementing a method of a interface?

Should an interface method implemented by a class always use all parameters? By interface I do not necessarily mean actual interfaces, these could be other (abstract) classes which are extended, too. ...
0
votes
0answers
59 views

Pass the parser to the sorter, or pass the sorter to the parser?

I have 2 objects that I'm not very certain what is the proper (or better) way I should use. I have a query builder object that constructs an SQL statement like $qb = new SelectQuery('users'); $qb-&...
4
votes
1answer
43 views

Correct Way to Implementing Authorization Checks in ASP MVC

In ASP MVC we have the Authorize attribute to perform check at either a controller level or at a controller method level. But what if you need to do check permissions inside a controller method e.g ...
4
votes
5answers
368 views

Is “too much methods” a valid reason to break the “composition over inheritance” rule?

I usually prefer to follow "composition over inheritance" rule, until I start stepping in the world of Java GUI. In my experience, for adding custom requirements in a GUI components, for example, add ...
2
votes
2answers
153 views

When is it ok to instantiate all of my objects upfront?

I am currently working with a contractor who's code instantiates a large number of objects upfront at the start of the application. This application is written in ruby, but I wonder how something ...
-2
votes
0answers
28 views

Need help in optimizing my arraylist class which contains combination of pair [closed]

Need help in optimizing my arraylist class which contains combination of pair: import java.util.ArrayList; import java.util.List; public class FieldsProvider2 { private MyObject object; private ...
0
votes
1answer
118 views

What's the OOP way of dealing with a flow control heavy application?

I'm refactoring a huge WPF application whose complexity stems from the way it deals with flow control. It has a lot of "tiny business rules" that make it really difficult to make a modification ...
2
votes
0answers
139 views

Is Nested Structure with Spread Responsibilities Not Logical?

Given the following code snippet in a Laravel Controller: $this->userRepository->saveByProject( $this->fileRepository->saveByProject( $this->metricRepository->...
2
votes
2answers
183 views

Class with methods that depend on a variable argument, but this variable is constant throughout large parts of the application

I am looking for advice on how to design the following scenario: I have a 3-dimensional vector class, the entries are of type double. I want two vectors to be considered equal if their corresponding ...
-1
votes
2answers
144 views

Is there a way to refactor the given code snippet without using if statement? [closed]

I am very new to java programming and I recently learned that using too many if else condition statements is not a good programming practice, and I am wondering is there a way to refactor the below ...
7
votes
3answers
313 views

Writing a good/readable constructor that needs a lot of calculation to fill its fields

I have a class that has several fields which can only be filled consecutively by a lot of calculation. The 1st field can be set very easily. To fill the 2nd field, we take the 1st field's content and ...
1
vote
1answer
150 views

Elevator design challenge [closed]

I need to strengthen my OOP skills and hence I thought to implement an Elevator simulator. At first what seem to be a simple design has grown into a complete mess and has left me confused about my ...
8
votes
2answers
280 views

Working with more efficient but less functional ways of storing data

Since learning object oriented programming I've been confused about how to deal with multiple ways of storing data that have different levels of functionality and efficiency. I'm kind of new to this ...
1
vote
1answer
72 views

What's polymorphic deployment

On pages 136 and 137 in The Clean Coder, Robert C. Martin describes how chips could be independently deployed thanks to a vtable: The solution was pretty simple. Each chip had to be decoupled from ...
-1
votes
3answers
137 views

What is the difference between this->data, and directly just data?

In C++ Is using this->data slower than data ?
1
vote
1answer
49 views

Does passing this as argument potentially cause exposure of invalid object state?

This question is based on two premises: First: an object must always have valid state. It is discussed in various posts, too. http://stackoverflow.com/questions/22408804/should-a-c-object-always-be-...
1
vote
1answer
90 views

Making a member function treat two objects differently in Python

I have in my program a class with a member function that should treat certain objects slightly differently than others. In order to do this, it needs to know which object was passed to it, because ...
1
vote
1answer
55 views

Recursive interface implementation causes empty method

TLDR: I have a situation where interface implementations accept other implementations of that very interface. Only a subselection of these interface implementations should carry a certain method - but ...
1
vote
1answer
136 views

Inheritance is better or composition design pattern in this scenario?

Design and implement Cash Register: Given a number of items you will be required to calculate the total bill. Items are charged for in a couple of different ways: A given price for each item, e.g. ...
3
votes
1answer
86 views

Regarding the Organization of Bit Shifting Utility Functions in C++

I am developing a project in C++ that deals with converting an ASCII hexadecimal string representation into binary. The class also has utilities in it for extracting info from the string. Right now ...
1
vote
1answer
156 views

Should we “prefer composition over multiple interface”?

Should we avoid multiple interface if possible? Because I think at most cases a class with multiple interfaces can be replaced with another version with composition and single interface only e.g.: ...
0
votes
2answers
187 views

How to avoid repeated instantiation and garbage collection for a trivial class?

I am developing a 2D tile-based RPG game for desktop and (hopefully) Android. To represent a tile location in the game, I am using a class called Location, which has a value for x, y, and room. room ...
-1
votes
1answer
157 views

Want Some Advice on Structuring My Text-Editing Program

I want to make a small command-line-run program that looks for a word or phrase in a target .txt. or .docx file, prints out a corresponding blurb about that phrase, and then replaces it with a ...
0
votes
0answers
68 views

Using Ruby ORM vs DB querying

If one were to set up an API in Sinatra connecting to MongoDB, is it absolutely necessary (or even a "best practise") to define models and use Mongoid (for example) to run DB operations such as User....
2
votes
1answer
106 views

Designing generic operations in object oriented languages

I found an interesting quote in SICP that I think is highly relevant in object oriented design: We see that, in general, a type may have more than one subtype. Triangles and quadrilaterals, for ...
1
vote
2answers
198 views

State Design Pattern

I've come across the following State Design Pattern which seems extremely logical and simple to implement: class CeilingFanPullChain { private State m_current_state; public ...
0
votes
2answers
153 views

Which pattern to use when I want to encapsulate large blocks of code?

I have a data structure, a large dictionary, that is mutated by several functions. Each function does a database call, some calculations and then changes the value of a key in the data structure. Each ...
2
votes
1answer
74 views

Is is ok to refer to object owned by root aggregate directly in this case?

While I'm trying to design classes based on DDD principles, I'm quite confused for this particular "pattern". For example, ScholarshipProgram contains many Cycle. They seem to be aggregate to me. ...
8
votes
3answers
561 views

How should an `Employee` class be designed?

I am trying to create a program for managing employees. I cannot, however, figure out how to design the Employee class. My goal is to be able to create and manipulate employee data on the database ...
0
votes
1answer
57 views

Dynamically create some types of array and return that array as a collection of arrays

As an example, I have database select query that returns n columns and I didn't know how many rows return (lets call x number of rows return). Sample code (c++ and SQLite): while (sqlite3_step(res) =...
6
votes
3answers
582 views

Is it better to expose or hide dependency in OOP?

Let's say I have an object A, which is too big(having too many methods and variables). So, I break it down to smaller objects. After that, I have Object A, B, and C. Obviously, Object A is from Class ...
0
votes
1answer
71 views

Are there any drawbacks to using two opposite listeners?

In OOP there is a common pattern of using listeners and events. Recently I've come upon a task where two opposite listeners were setup to accomplish needed logic: private ValueChanger ...
4
votes
1answer
407 views

Clean OOP-Design: How to implement single responsibility and no procedural programming

I am currently trying to refactor a piece of C# code that is somewhat procedurally written. I want to make the design clean, object oriented and using classes with single responsibilities. The code ...
0
votes
0answers
42 views

Should I split function reference into a class reference and method reference?

We have code like ['Index::Show::AjaxPost', ...] which references a function AjaxPost in Index::Show module. I was ordained to refactor it in object oriented manner. Should I split it into [['Index::...
-3
votes
1answer
300 views

What is disinheritance in object oriented programming? [closed]

I am confused over Virtual Inheritance and disinheritance ? Is both are same ?
0
votes
0answers
108 views

A modification of singleton pattern

"Singleton" is widely considered anti-pattern ("bad" in everyday language). What about this alternative modified singleton pattern? An object constructor for our class ensures that at any given ...
0
votes
2answers
92 views

Static factory method in base class

An increasingly popular definition of factory method is: a static method of a class that returns an object of that class' type. But unlike a constructor, the actual object it returns might be an ...
0
votes
0answers
33 views

Choosing class names and relations for different user scopes

I am developing an online Order Management System using PHP in which I have some different behavioural scopes regarding the User class: some user scope under which the chronological transactions are ...
0
votes
1answer
113 views

How to search through an array of objects?

I am using an array of objects to store data to render a page. A few examples of the type of data each object can contain: PHP filepath for an include CSS filepath for CSS files Meta data of the ...
1
vote
2answers
78 views

How do you represent an object when you need to know which subtype you're working with?

I have some data that I need to represent in a form. As an example, it might look like this (in psuedo-json): [ { "value1" : "int" "value2" : "{1, 2, 3, 4, 5}" "value3" : "...
3
votes
0answers
58 views

Where should view-specific data/logic be defined in a PHP MVC application?

After many hours of research and thinking I have found an understanding, then coming to question it again, I am struggling to find something concrete which I can grasp and apply to my code in a ...
0
votes
1answer
167 views

Should I force “composition over inheritance” rule to class members?

As I know, according to "composition over inheritance" rule, we should avoid reuse a method by inheritance, but how about class members? Suppose I have parent and child classes: public class Animal{ ...
0
votes
0answers
42 views

Export a method vs using a boolean property in a class?

I am writing a base class with common code for several Web sites. Two of these sites have mobile support. Should I create (constant) boolean object property mobile_support and write if(site->...
4
votes
3answers
184 views

Role and importance of static method in OOP

Background Thinking about OOP I feel that it binds data and behavior together, taking the real world example we already have array data type which is a collection of homogeneous type but in Java we ...