Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [object-oriented]

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

0
votes
1answer
543 views

Why does the Square–Rectangle problem violate SOLID principles?

My previous question was just with class diagram and because of some comments I thought I try to find an example with a little piece of code for the diagram to see if principles correct understood? ...
-2
votes
1answer
65 views

looking to solidify understanding of OOP principles

I just wanted some feedback on my definitions of these terms. Abstraction - only showing relevant information and hiding implementation details. Interfaces and abstract classes are an examples of ...
1
vote
2answers
386 views

Which SOLID principles are broken by this class diagram?

I just read about all the 5 principles S,O,L,I,D and I like test it in little example if I understand them correct. Which SOLID principles are hurt by this class diagram? I think what is broken is ...
0
votes
2answers
78 views

Singleton's applicability clarification

According to the GOF Design patterns' book, singleton pattern should be used when: there must be exactly one instance of a class, and it must be accessible to clients from a well-known access ...
1
vote
2answers
155 views

Encapsulation and input validation duplication

Consider the following example (very simplified): public class Basket { private readonly List<BasketItem> _items = new List<BasketItem>(); public IReadOnlyCollection<BasketItem&...
0
votes
3answers
72 views

Nesting Objects without Passing Arguments?

I have a couple of classes that I've nested together (not in the sense you may think so bare with me), to create what I call a prefab object (similar to Unity's prefab system). In this particular ...
1
vote
1answer
71 views

Common Code for Transformation of an Entity

My api is exposing information centering around an entity Company. Companies are complex, and can contain Vendors directly, or can contain sub-companies which contain vendors themselves. A consumer ...
2
votes
4answers
215 views

“Duck-type-y” interface/implementation

I do not know the "correct" name of that pattern, so I'd like to describe it with a simple example. In C#, System.Windows.Window contains a ShowDialog method. I can define an interface containing ...
4
votes
1answer
278 views

Wrapping utility classes and injecting them for unit testing purposes

I found that it is so hard to test classes that depend on other utility classes as java.nio.file.Files. It is also impossible to mock them using the classic unit testing stack (junit,mockito,..) ...
3
votes
3answers
262 views

Are there any drawbacks to using a nested class instead of declaring a new one?

I'm doing code review on a change my co-worker made to our Java application, and I've found something I'm not very familiar with - a nested class. From reviewing the code, it seems like the nested ...
2
votes
4answers
203 views

Creating new constructors to overwrite the existing instance variables for testing purpose

Is it good/bad practice to add more constructors just for test purposes (to mock the DOCs used in my SUT) like this : public class A { private B b = new B(); private C c = new C(); ...
3
votes
2answers
408 views

C++ Gof Design Patterns heavily depends on new or shared_ptr

I'm trying to learn the best practices for code design and reuse in C++ so I am going through the well known GoF Design Patterns Elements of Reusable Object-Oriented Software. I noticed that nearly ...
6
votes
3answers
725 views

Can the Flyweight Pattern be used with mutable objects or not?

I recently learned about Flyweight Pattern from this link. It is written there: It’s very important that the flyweight objects are immutable: any operation on the state must be performed by the ...
0
votes
2answers
222 views

OOP design problem with Java

I have part of the system that looks like this: Basically, the client decides which API call to invoke on the server based on the flag that is previously provided. It knows in advance which type of ...
0
votes
2answers
153 views

Where should permissions be stored in a micro services architecture

We are currently in the process of building a service (a REST API) which is called on by our primary application. The primary application contains a users/permissions/roles set up which is used to ...
2
votes
1answer
198 views

How do I use polymorphism instead of instanceof?

I'm trying to make an abstract board game. In the game, a player can choose to make multiple actions within one turn such as placing, moving, or rotating a piece. I'm not sure if whether or not my ...
0
votes
4answers
191 views

Preferred method of accessing an external class of methods through the original class

I want to move a bunch of similar methods to an external class. The class is initialized with the original class instance. From there I can access it either by property (persistent instance) or by ...
1
vote
1answer
94 views

Pure functions with a connection to a system

What's a good place to put pure functions that have connections to a system? public class Core { System system; } public class System { SubSystem subSystem; // subSystem.Multiply(a, b); }...
0
votes
1answer
219 views

Should the function that operates on the object return it?

Should the function that operates on the object return it? Shortened example: class Example1 { public function method($a, $b) { $result = new Result($a, $b); $this->...
0
votes
1answer
279 views

Why isn't there a static initializer in Python?

The equivalent of static { // Code here } does not exist in Python by default. The closest thing, while being "Pythonic", seems to be to create a decorator and do the initialization there such ...
0
votes
1answer
145 views

freeRTOS C++11 queue with pointers inside, object-oriented

I thought about this problem I was having. I have producer-consumer type of design with two user-created-tasks sender, and reader. Queue is used to communicate between reader-sender. Currently the ...
0
votes
1answer
105 views

How do you call a class that is inheriting another class?

If class is declared like this class Foo : IFoo From IFoo point of view, Foo is called implementation. If class is declared like this class Foo : Bar Then Foo derives from Bar. How do you call a ...
0
votes
1answer
120 views

Can a class factory also save the object to a database?

How can a factory also save the object in the database? I want to create an object that consists of other objects. Pseudocode: firstObject = db.get....; secondObject = db.get....; expectedObject = ...
0
votes
1answer
129 views

What's the benefit of separating specialised data from behaviour in an algorithm?

Functional programming strongly suggests to separate data from behaviours (functions). However, I can't see the benefit of this for an algorithm's implementation intrinsically tied with particular ...
0
votes
3answers
724 views

Calculating the total price of items in a shopping cart

I am making a shopping cart. A shopping cart will have a total amount of money you've got to pay for the products you've selected. I'd like to approach the problem using both OOP (encapsulating it) ...
2
votes
5answers
527 views

Is it safe to put SQL statements in my C# application?

I'm making a medium sized application to be distributed privately to several Churches. It connects to an Azure database but it does not have any server managing the information (apart from the SQL ...
2
votes
2answers
155 views

The main reason for using the command design pattern for game AI

I've been going through all the design patterns in context of game programming form this book, before starting my next big project. Apart from that I've been reading about them in more general context....
0
votes
1answer
111 views

C++11 freeRTOS questions about queue usage and object design

Background I'm writing C++ firmware with freertos to penplottingrobot. It's a makeblock XYplotter and the firmware is connecting to mDraw software for command instructions thru USB drivers. MDraw ...
2
votes
2answers
391 views

Is it bad practice when an Object has to be aware of another Object

I was reading this page and came across this sentence in the accepted answer: I don't like A directly knowing about B. But that's a DIP thing not a POJO thing. What if you can't abstract out B ...
22
votes
6answers
1k views

continuous integration for scientific software

I'm no software engineer. I'm a phd student in the field of geoscience. Almost two years ago I started programming a scientific software. I never used continuous integration (CI), mainly because at ...
-3
votes
3answers
128 views

OOP and class that inherit from many classes

In OOP, is it possible to have a class that inherits from multiple other classes? And if yes, how is this situation called? For example, suppose I have the following classes: Eye Nose Mouth Eyebrow ...
1
vote
1answer
66 views

Should I group all sound file definitions together? Or define some of them locally, if possible?

For example, suppose my application have some sound files, now I define all sound file references in a single class: public class SoundHelper{ public static Sound buttonSound=new Sound("(some url)...
1
vote
2answers
122 views

Architecture for slot machine game

I am building a slot machine game for a client (virtual money, not real-money gambling). They started out with a template game and hired me to reskin it and make "minor" changes for a "quick" release. ...
0
votes
1answer
46 views

Accessing an object accross different view functions in Flask

I am experimenting with an web app for searching and buying bus tickets. I came up with a few objects like RequestedRoute, Passenger, and Ticket: I have some Flask view functions as well. The home ...
1
vote
0answers
35 views

Splitting aggregate leads to inconsistencies in data

What I'm going for is something like GNUCash or any type of personal finance tracking software that looks similar to this: That is the main page listing all your accounts; then when you click an ...
1
vote
1answer
142 views

Why is using an internal attribute to filter objects considered OK, but when I use a map to filter based on attributes, it's considered a code smell?

A long time ago I asked about using an enum to essentially use as a poor version of instanceof to make decisions about an object. As stated in this answer: When your weapon types enum just mirrors ...
-1
votes
1answer
116 views

Have an object communicate with another object

I asked similar question earlier this morning, and for whatever reason, I'm not getting a complete answer to my question. I'll ask it a different way. I was attempting to understand Eric Lippert's ...
2
votes
2answers
97 views

Using a Collection with Attributes to Check and Make Decisions

I was reading on this SESE page about using a variable to indicate the object type, more specifically, an enum. The accepted answer states: When your weapon types enum just mirrors the class ...
1
vote
4answers
114 views

High class cohesion violates ubiquitous domain language

Originally posted at CodeReview, but it was brought up that this would be better posted here. The other question has been deleted. Creating some personal finance software, but running into an ...
2
votes
3answers
246 views

Why is the Command desing pattern useful for game AI?

I'm trying to learn the Command design pattern and apply it to the game I'm working on. First I read about the general implementation, and I feel like I understand it pretty well. Now I want to know ...
4
votes
1answer
408 views

Why do we imlpement the Command design pattern like this?

I trying to learn the Command design pattern, I already know how it works and where it is used, but I'm a little bit confused about the implementation. So I know we need to set the context by ...
1
vote
2answers
81 views

Appropriate design for restoration of previous states

This is a very common feature in software, and I am sure there is a whole deal written about it, but I really don't know what the technical term is, so here I am: I am talking about giving your ...
2
votes
0answers
139 views

Separate business logic from ORM models in SQLAlchemy

I have a Flask application with tens of complex models, almost all of them related to each other. A simple pseudo-schema of some of them: +----------------+ | FoodGroup | +-------+--------+ ...
1
vote
2answers
94 views

Performing serial communication in constructor to initialize an object

I have a class UnitInfo which represents a collection of unit information with methods to get the unit information in a structured way, such as a specific encoding, etc. This unit info consists of ...
1
vote
0answers
74 views

Expected behavior from client when thinking about design patterns?

I'm confused about the behavior I should expect from a client when thinking about design patterns. To be more precise, I'm reading the Head First Design Patterns book, and on the difference between ...
0
votes
2answers
73 views

Is it a good idea to let database surrogate key values spill out into other aspects of code (HTML, Controllers, Model, Repository layer)?

Is it acceptable to use id in HTML forms and subsequent code processing (controller, view, model, repository layers)? For example I need to show something like this on a web page: Select Motor ...
0
votes
1answer
115 views

Is this a 'proper' use of a trait in PHP?

In Laravel 5.6 an Illuminate\Database\Eloquent\Relations\BelongsTo relation was given the ability to support default models. This allows a model that will be returned if the relationship is empty. ...
1
vote
1answer
46 views

Using the objects retrieved at the time of request validation

I hope the question title already answers the subject here. Lets say I have a number of ids that needs to be validated in a request. Example: request uri: [POST] /album/{album_id}/song Request ...
1
vote
0answers
70 views

Hierarchy of models while designing a client for a RESTful service

I am trying to write a client for a restful service. I am confused in designing the models. Below are the details: I have a Model named UnicastMessageRequest, it's definition is like this: ...
4
votes
2answers
188 views

Verifying Parameters in Constructor or Service

I was reading on this SO page about when to check parameters when constructing an object. The accepted answer suggests throwing the exception from the constructor so that an invalid object cannot be ...