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

learn more… | top users | synonyms

4
votes
3answers
3k views

Why shouldn't an object reference have access to a static member in C#

Context of my question: I am reading C#. Trying to understand Static keyword. I understand that when Static is applied to a member of a class, it can only be modified by the class and not the class ...
25
votes
7answers
13k views

Why avoid Java Inheritance “Extends”

Jame Gosling said “You should avoid implementation inheritance whenever possible.” and instead, use interface inheritance. But why? How can we avoid inheriting the structure of an object using ...
0
votes
0answers
91 views

Interaction between code and user interface

I'm developing a desktop app that has many different algorithms implemented. Some algorithms require additional input from user, this info might not be known before algorithm has started. My ...
-1
votes
0answers
45 views

What classes should I use for API -> logic -> API?

I need to fetch some information from an API, parse through it and push the relevant data to another API. How should I design this? One class handling everything? One class per API and one for the ...
37
votes
7answers
6k views

Why is chaining setters unconventional?

Having chaining implemented on beans is very handy: no need for overloading constructors, mega constructors, factories, and gives you increased readability. I can't think of any downsides, unless you ...
0
votes
1answer
150 views

Object Communication Design

Multiple top-level systems that communicate with each other via messages(events/commands). The Main class of the program wraps around all the systems and has a message dispacher component wich ...
3
votes
1answer
471 views

Teaching Programming: drawbacks of using unit tests in problem statement for assignments? [closed]

I am experimenting with marking assignments for a programming course using unit tests. Is it likely to harm the learning process if I publish some of the tests I use as part of the problem statement? ...
1
vote
1answer
205 views

How should one model an ExchangeService object (in ews-java-api) for sharing MS Exchange connections?

I am creating an application which uses ews-java-api to connect to an MS Exchange server. Once the connection is authenticated, the api dictates use of ExchangeService object for searching mailboxes, ...
3
votes
0answers
81 views

Finite state machine menu design

I'm creating a FSM in python (it's a step sequencer and sample pad based on a Raspberry Pi 2). Right now there are two states and the third is the Menu. This is handled by a class System which ...
1
vote
0answers
45 views

Message Mapper Design Considerations

Long question context, skip to tl;dr for the meat of it. I am designing an integration between two web applications, and have come to the conclusion that a message pattern would be an appropriate ...
0
votes
0answers
95 views

Option<T> functional type implementation and scenarios

Have you ever being implementing Option<T> functional type? It is discussed here: https://app.pluralsight.com/library/courses/tactical-design-patterns-dot-net-control-flow/table-of-contents ...
0
votes
1answer
93 views

Can I enforce the overriding of GetHashCode() and Equals() methods for users of a generic container class?

I have a container class similar to the one below (with much of the logic omitted): class Container<T> { Dictionary<T, TWrapped> contains = new Dictionary<T, TWrapper>(); ...
74
votes
16answers
57k views

Is it better to return NULL or empty values from functions/methods where the return value is not present?

I am looking for a recommendation here. I am struggling with whether it is better to return NULL or an empty value from a method when the return value is not present or cannot be determined. Take ...
0
votes
1answer
246 views

How to better isolate JOGL or LWJGL3 dependency from game clients?

I'm currently working on a project to develop a relatively small framework with the goal of supporting game development efforts for students in a course. The scope of this project is an OpenGL-based ...
6
votes
1answer
109 views

Software design: recommend approach to avoid slicing/type erasure here

Here is a concrete minimal example to formulate my question : In small ball game, you have a physics engine that moves the objects regularly: void move(set< PhysicalObject* > objets, Duration ...
2
votes
2answers
362 views

How/when to “build” a Singleton that stores configuration data

I am a junior developer (think "intern-level" experience) working at a small shop more or less alone on a project that consumes data from a database, processes it, and inserts the results into another ...
24
votes
6answers
3k views

Is there a design pattern to remove the need to check for flags?

I'm going to save some string payload in the database. I have two global configurations: encryption compression These can be enabled or disabled using the configuration in a way that either only ...
9
votes
2answers
186 views

Programming to Data Oriented Interfaces

There is a portion of our codebase written in the following style: // IScheduledTask.cs public interface IScheduledTask { string TaskName { get; set; } int TaskPriority { get; set; } ...
0
votes
2answers
79 views

Which design pattern to choose when supporting multiple analytic tools?

I have spent quite some time learning all possible design patterns but I cannot find the ideal one for the following case. I am developing an iOS app where we are using multiple analytics tools like ...
5
votes
3answers
457 views

How to solve circular dependency?

I have three classes that are circular dependant to each other: TestExecuter execute requests of TestScenario and save a report file using ReportGenerator class. So: TestExecuter depends on ...
22
votes
12answers
2k views

Object Oriented Design

Suppose you have the following: +--------+ +------+ | Animal | | Food | +-+------+ +----+-+ ^ ^ | | | | ...
9
votes
8answers
778 views

Designs and practices to guard against erroneous null entries from database

One part of my program fetches data from many tables and columns in my database for processing. Some of the columns might be null, but in the current processing context that is an error. This should ...
16
votes
8answers
2k views

Refactoring a long method which is based on large number of switch cases [duplicate]

We are using Java as a backend development language. One year back, we wrote a method which uses switch cases based on Enums values. Since we are continuously adding enum members and according adding ...
12
votes
4answers
904 views

How does having too many instance variables lead to duplicate code?

According to Refactoring to Patterns: When a class is trying to do too much, it often shows up as too many instance variables. When a class has too many instance variables, duplicated code ...
3
votes
5answers
282 views

Inheritance when following the Repository Pattern in PHP

I am trying to build a PHP application using the Repository Pattern but I'm not sure how I should implement the save method. I have an abstract class called ItemRepository which have the following ...
3
votes
5answers
128 views

Can encapsulation be implemented by proper types rather than accessors?

Interesting question came up while designing interfaces at work, now resolved, but I want to ask about the theory behind it. Is it incorrect to say that properly typed data members of a class provide ...
2
votes
2answers
402 views

Updating an Entity through a Service

I'm separating my software into three main layers (maybe tiers would be a better term): Presentation ('Views') Business logic ('Services' and 'Repositories') Data access ('Entities' (e.g. ...
2
votes
1answer
100 views

Pass request as argument to service client vs. pass service client as argument to request [closed]

I need a design recommendation: I have a class that send a http request via another class WebServiceHandler() I am hesitating between the following two implementations, which one to choose?which one ...
3
votes
1answer
105 views

Does my design break modularity and loose coupling?

I want to know if my implementation is modular and loosely coupled such that pieces can be replaced easily. Any concrete class that extends the abstract class HexGridLayout will be expected to ...
4
votes
2answers
646 views

Python classes with only one instance: When to create a (single) class instance and when to work with the class instead?

Given a Python class which will be instantiated only once, i.e. there will be only one object of the class. I was wondering in which cases it makes sense to create a single class instance instead of ...
2
votes
2answers
105 views

Should the Vector type inherit from the Array type in an environment where both are first-class objects

I have created a programming language that is based on java for a personal project. The language already has generic classes and functions and the generics are completely compatible with primitive ...
5
votes
4answers
324 views

Dependency Inversion Principle and Hollywood analogy

Often DIP is known as the Hollywood principle: "Don't call us, we'll call you.". But doesn't always higher level module calls lower level module, whether there is dependency inversion or not? Then ...
0
votes
0answers
17 views

Which design pattern for interaction with miscoded project [duplicate]

I am actually working on JavaEE application (Spring, Hibernate). I have an old project which is not well coded. I have to not modify any line of code on it. And I have to add classes that uses this ...
3
votes
4answers
547 views

Separation of construction and initialization

I'm confused by this post by Mark Seeman. And his comment on IInitializable below: The problem with an Initialize method is the same as with Property Injection (A.K.A. Setter Injection): it ...
-1
votes
0answers
8 views

What design pattern is best for the following scenario and how to apply it?

1- if a developer is designing a game where the game receives different kind of stimuli in which is determined by the current state of the game. The behavior of the game could be described as below; ...
44
votes
3answers
10k views

Rich Domain Models — how, exactly, does behavior fit in?

In the debate of Rich vs. Anemic domain models, the internet is full of philosophical advice but short on authoritative examples. The objective of this question is to find definitive guidelines and ...
1
vote
1answer
141 views

When should interface be owned by client?

In Agile Software Development: Principles, Patterns, and Practices, Uncle Bob talks about client owning the service interface. My questions are : Should client always own the interface or only ...
0
votes
0answers
91 views

Generic Type Parameters where one is itself Generic with a Type Parameter of the Other

I have a couple of classes with the following pattern that I am uncomfortable with. Is this the only way to do this, or are their other design patterns that would be more reliable. public class ...
0
votes
2answers
141 views

two repositories with kind of different behavior serving same object

I have a simple object like this public class Book { public List Chapters { get; private set; } public TableOfContent BookTOC { get; set; } public string Identifier { ...
2
votes
1answer
184 views

How to implement a facade correctly

I have read multiple websites on this topic but none of them gave me a 'good' solution for the problem I am having. The problem is described in the following (related) questions: How do I couple the ...
-3
votes
1answer
124 views

Is there a pattern to map a range of numbers to a string?

I need a function that will take the name of a town and return a specific range of numbers that is assigned to that town. I won't be using a database. The simplest way to do this is //Pseudocode ...
1
vote
3answers
114 views

How To Extend Parent Methods in Children Classes?

There is a parent class with a method which many children use but many children extend the method, what is the best way to extend it without violating DRY? Here are my 2 current solutions: 1: The ...
12
votes
4answers
950 views

Switch vs Polymorphism when dealing with model and view

I can't figure out a better solution to my problem. I have a view controller that presents a list of elements. Those elements are models that can be an instance of B, C, D, etc and inherit from A. So ...
2
votes
3answers
302 views

Is this avoiding inheritance correctly?

I want to add capabilities for an abstract Model class to send events whenever it updates. To be able to send events, it needs to have access to an EventManager. So, the intent were first, to be able ...
5
votes
1answer
90 views

Object-Oriented design to create Images in Python

I'm creating images with centered text. I use Python but I'm faced with many question regarding how to write my class. I know that A class must aim to do one thing and do it well. Well, the ...
6
votes
5answers
1k views

Does this code solve the square/rectangle Liskov Substution Principle example?

I just wanted to check that I understand the LSP correctly and can solve it. I am taking the classic rectangle/square problem and attempting a solution: class Rectangle{ public $width; ...
0
votes
1answer
110 views

Should I hold an Id and the Item [duplicate]

Let's say I have a Customer which contains an Address class like: public class Customer { public int Id { get; set; } public string FirstName { get; set; } public string LastName { get; ...
6
votes
2answers
285 views

Automatic namespace resolution in C++

My question is focused on design, and the code included in this question is meant to clarify the problem I'm experiencing. I'm interested in conceptual level answers and not code in order to answer ...
2
votes
2answers
137 views

Private variables and the old FORTRAN common blocks [closed]

This is a question that perplexes me about object oriented programming. In some OOP languages (e.g. C++) a member function can access private variables of the class without restriction. That means ...
3
votes
1answer
179 views

Why is abstract Decorator class needed in this example?

Why do we need ShapeDecorator in this design? Why can't we just have RedShapeDecorator implement Shape directly and inherit from Shape?