Stack Exchange Network

Stack Exchange network consists of 174 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-design]

Object-oriented design is the process of planning a system of interacting objects for the purpose of solving a software problem.

1
vote
1answer
65 views

Can I avoid using variable types that bypass type checking when using a library that provides largely identical but unrelated models?

I have a situation whereby I'm using a library that's been generated to provide an XML interface in C# based upon an XSD file run through xsd.exe. The XML is structured as so. -Results -ModelA ...
1
vote
2answers
113 views

Comparing approaches of mapping data objects

Update: I added some diagrams to help understanding I had a discussion with a colleague about two different approaches in mapping data objects. I'd like to get your opinion on pros and cons between ...
3
votes
2answers
193 views

Best practice for keeping legacy models in code?

On my first part-time programming gig during college, I dealt with a large-ish web application responsible for handling a periodic event hosted by our client, largely a plain CRUD snoozefest with a ...
0
votes
1answer
57 views

Method grouping other methods of the same family and how to call any of these separately

Worse title ever but I don't really know how to describe my scenario in a line... So I have a method that wraps the calls of a many methods of the same nature. Once any of these methods have finished,...
1
vote
1answer
88 views

How to make an interface and its implementations compatible

In a competition application I'm designing there are several types of prize draw, each of which needs to act upon an entry object in some way. So the first lines of code I wrote defined an interface. ...
5
votes
2answers
256 views

Is it wrong to use any type of parameter to determine behavior?

According to Is it wrong to use a boolean parameter to determine behavior?, I should not use a boolean parameter to switch behavior inside a function. How about other types of parameters? For example,...
0
votes
1answer
227 views

Using methods specific to a subclass

I came across this SESE page: What is a proper use of downcasting? (for C#) -- and it talks about when to downcast, and the possible downsides to it. In Python sub classes are slightly different ...
2
votes
5answers
523 views

What should a constructor contain?

What should a constructor contain? In both cases, all three arguments are needed for the class to work. Which approach is better and why? 1) class Language { LanguageRepository ...
0
votes
0answers
37 views

Access not similar configs with one data access object

I'm currently working on a little project and hope to get better with software design. I have a solution, but I think there is a much a better way I’m not aware of. The problem is each config needs a ...
0
votes
0answers
103 views

How to implement strategy pattern in context of few key elements on every page?

This is my concern: I need to generate content for <title> <h1> and <meta name="description"> tags, that will affect ~ 100 000 pages. Basically, it is a SEO optimization. ...
0
votes
1answer
159 views

Design Pattern for doing things in sequence and being testable

I'm working on an application which contains an element that needs to make several http calls in a set order, to perform an action successfully. (Interfacing with an external system's API.) We have ...
-2
votes
4answers
123 views

One Single Table or Two Smaller Tables

We currently have a Users table in the database, this has quite a few columns in it. Around 50% of the columns are barely used in the system (only on one or two pages). We've been discussing amongst ...
-1
votes
2answers
112 views

OOP Design Choices in a Web App

I am about to start coding for a school project that requires me to demonstrate good OO practices in a web app. Now, I have built a few web apps and have never felt the need to define my own classes ...
5
votes
2answers
213 views

Is wrapping a hardware resource using polymorphism going too far?

I am writing a simulation engine consisting of a number of components, each of which operates on a fixed set of shared buffers. In practice, the simulation will run entirely on the GPU. When ...
12
votes
2answers
373 views

How to avoid duplication of data structures when parts of an app are written in different languages?

As an example, say you are writing an app in Java. Your app communicates with an API server written in Python. The Python server communicates with an SQL database. You also have a website for your ...
1
vote
3answers
241 views

design pattern for class with data attached

I have a class Tiles that looks something like this: class Tiles { public: void AddTile(int x) { tiles_.push_back(x); } std::vector<int> tiles_; } Now I want to create a class Tiles with ...
1
vote
1answer
55 views

Setting a parameter to null with two-parametered interface method

I have a couple of classes that are doing the same thing: filling a series of object using data sources passed as a parameter. As I need two distinct of them, my interface holds the following contract:...
-2
votes
1answer
105 views

Splitting up a class

I have a Report class that is basically an interface for creating HTML reports generated via a Python template engine. The Report class currently generates the report but also has a few methods ...
2
votes
1answer
110 views

Think of a better method name or create separate functions for a possible single responsibility?

I'm still currently learning OOP. I need a method that takes in a List<JsonNode>. Now there are multiple components that need some resources from the List. Component1 needs all of the keys. ...
3
votes
2answers
180 views

Avoinding circular dependency

I am building a fleet unit gps system and currently and i need to figure out how to link my objects. Here is the scenario: Each fleet unit may have attached one or more gps devices. Each fleet unit ...
1
vote
2answers
155 views

Save not-so dynamic data into a database and retrieve with changes in the future

Imagine this use case: I have a class with 50 attributes of which 10 are relationships plus 100 methods which perform calculations and return a value. I need to save that data (including ...
0
votes
1answer
40 views

Object Responsibility and Calculations

Trying to work out where certain responsibilities lie with the following example. We have a Project object and a Project can have Time entries booked against it. Each Time entry will have a no. of ...
5
votes
1answer
339 views

Design Patterns to model complex decision graph

I am currently building a piece of code that creates side-effects based on input parameters. It has around ten input parameters and about six available side-effects. Based on the input parameters, the ...
3
votes
2answers
314 views

Liskov principle: subclasses can have stronger invariants. How could it work?

Learning about the Liskov principle, I do understand that preconditions can be weakened and postconditions can be stronger in subtypes. However, I do not understand how invariants can be stronger in ...
7
votes
3answers
302 views

How to be OCP compliant and change algoritms?

I am not working yet, just studying and recently dealing with SOLID principles. I have read quite a lot about open closed principle but unfortunately most of the books and articles share the same ...
21
votes
4answers
3k views

Use abstract class in C# as definition

As a C++ developer I'm quite used to C++ header files, and find it beneficial to have some kind of forced "documentation" inside the code. I usually have a bad time when I have to read some C# code ...
4
votes
4answers
162 views

Using a Break or Return instead of setting a Flag [duplicate]

I was reading on this page about setting a flag in a loop and using it later. Most of the answers agreed that it's a code smell. One of the answers suggested refactoring the code by putting the loop ...
4
votes
1answer
5k views

Are Spring beans declared as static a poor design choice?

The question is pretty straightforward, I'll try to explain why I want some explainations. (All of this is my 1½-year junior Java developer opinion, which may be more than incomplete. Which is why I ...
0
votes
3answers
165 views

Documenting my code using generic Design Patterns interfaces

Background I've been thinking about documenting design patterns in our code by setting up interfaces for the common design patterns so that when people read my code it would be clear that I am using ...
30
votes
7answers
11k views

Is it a code smell to set a flag in a loop to use it later?

I have a piece of code where I iterate a map until a certain condition is true and then later on use that condition to do some more stuff. Example: Map<BigInteger, List<String>> map = ...
1
vote
1answer
159 views

Mediator pattern or facade or …?

I'm writing an app which tracks device location and based on some factors (user gets an assignment), it needs to change the location tracking settings (for example, frequency). I have an issue with ...
3
votes
3answers
170 views

Liskov substitution for voids and weakened preconditions

I am learning a lot about this principle (also thanks to two answers I received here) and would like to elaborate on another point that somebody mentioned. 1) Is the following a violation of LSP? ...
0
votes
2answers
310 views

Design Pattern - Add new functionality to an abstract class

Imagine I have an abstract class Node which has several methods and attributes. (Join a network, send a message, broadcast ...). I want to be able to add/remove functionality to/from that Node class (...
-3
votes
1answer
69 views

How to design classes and db table in right way for recurring Order?

I have requirement like user can booked space (office, room, meeting room etc) for a rent for particular time period. But requirement is like user required to booked space every month 5th date, or ...
1
vote
1answer
128 views

What is the name given to the practice/pattern of exposing properties of properties as immediate properties? [closed]

I believe there is a person who named this pattern or practice and would like to know the correct nomenclature to avoid confusion. object.propertyA.propertyB becomes object.propertyB
1
vote
2answers
59 views

__init__ arguments differ from object attributes

Is the following class definition a good design? class Myclass: def __init__(self,num1,num2): self.complicated_tree = __class__.object_creator(num1,num2) @classmethod def ...
0
votes
0answers
64 views

Design pattern which could suit for startup initialization of static variables before an engine starts serving its request

I should initialise the startup variables before serving the requests. Few of my variables could be initialised from local property file (say init.properties) and few would get initialised from an url ...
4
votes
2answers
318 views

Identify methods on OOP

I am struggling to define methods in OOP. Currently I am practicing with this scenario: "A hospital has started the development of a new system to keep records of analysis done by patients and the ...
39
votes
13answers
9k views

Is it wrong to use a boolean parameter to determine values?

According to Is it wrong to use a boolean parameter to determine behavior?, I know the importance of avoid using boolean parameters to determine a behaviour, eg: original version public void ...
2
votes
0answers
89 views

Access modifiers in combination of interpreter pattern with template method pattern

Motivation: (Skip to "The Problem" if you don't need motivation for it) As a project for myself, I'm writing an expression parser for certain kinds of mathematical expressions, and I'm using the ...
2
votes
4answers
553 views

What is the benefit of short readable code if you only see functions and classes on the outside?

Last years I made myself familiar with Python and Haskell. I am surprised and impressed about the short and readable code you can write in these 2 languages, especially in comparison to languages like ...
3
votes
1answer
119 views

Looking for a strategy to ensure name of child node stays unique in collection

Even though I'm programming in PHP, I'm open to reviewing language-agnostic suggestions, as they might point me to valuable directions. To remove any possible confusion I feel some comments appear to ...
1
vote
1answer
301 views

How to organize the management of resources for OpenGL?

I write my own 3D-graphics engine for education and have some difficulties with it's architecture. I wrote classes like OpenGLTexure, OpenGLMaterial, OpenGLGpuProgram, etc. I also wrote a class ...
4
votes
2answers
135 views

Composition and calling part methods

What is the right concept of calling methods of parts in composition? I have a class class Body{ Arm arm; } class Arm{ public void waveArm(){} Finger finger } class Finger{ public void ...
0
votes
4answers
202 views

What are the relevant design patterns to perform validations on an object?

I have a typical use case where i am consuming to a message broker. The messages are <^> delimited strings. I parse each and every message create POJO's and then apply different validations to ...
1
vote
1answer
59 views

How to handle extra steps that are part of concrete class generically in template method design pattern?

I have a set of operations that need to be executed as part of large process and subclasses may slightly differ part of the step. This problem seem to be solved by using the Template Method design ...
2
votes
1answer
803 views

php class composition: how to implement “has a” relationship in the case of a DAL

I'm learning about OOD and good practices in OOP and find myself struggling with some key concepts. As a practice I'm rewriting my custom PDO database abstraction layer which used to be a single file ...
4
votes
1answer
215 views

A Memento by any other name?

The GoF book "Design Patterns" describes the Memento pattern as an object encapsulating its state in a separate object. However, the book specifically describes the memento for use with a specific ...
3
votes
1answer
93 views

How can I be sure that subclass set a (mandatory) property in it's constructor?

I have a base class called ProductRepository and there are other classes which extends it; such as PushProductRepository or SocialProductRepository. class ProductRepository implements ...
5
votes
6answers
338 views

Exposing member variables vs Adding member functions to modify them

Say that we have a class Car that contains objects of type Wheel class Wheel { public: void SetFriction(double f) { friction = f; } private: double friction; }; class Car { ...