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

3
votes
3answers
2k views

When should the builder design pattern be used?

I am currently learning about various object oriented design patterns. I came across a pattern called the builder pattern which is basically where you build a complex object through the use of ...
5
votes
1answer
8k 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 explanations. (All of this is my 1½-year junior Java developer opinion, which may be more than incomplete. Which is why I ...
-3
votes
1answer
65 views

Should I not use inheritance when I need subtype cast/instantiation from basetype?

Problem BaseType has a field String jsonData that represents a JSON string. The structure of the JSON string differs according to a field String dataType. SubTypeA, SubTypeB, SubTypeC all extends ...
25
votes
3answers
46k views

When to use a Singleton and when to use a static class [duplicate]

I've searched about this here and on StackOverflow and found some differences between the two. But I'm still not sure in what cases one would prefer a Singleton, and in what cases one would choose to ...
66
votes
7answers
70k views

Why have private static methods?

I just wanted to clear up a question I have. What is the point of having a private static method as opposed to a normal method with private visibility? I would have thought an advantage to having a ...
0
votes
1answer
64 views

Clean code for multiple entity representations

I'm wondering what is a clean solution for representing an entity in many different format. Let's suppose I have the following entity: Person { Long id; String title; String firstName; ...
3
votes
2answers
773 views

How to think in Object Oriented way when it comes to passing messages?

Somewhere I have read that "Object Oriented" is a misnomer and that OO should really stand for "message-oriented programming". What I am not clear about is ... what does it mean? For example in ...
0
votes
4answers
1k views

Why is Java not 'pure' OOP? [duplicate]

Java is designed in a very OO approach, and somewhat even 'forces' programmers to program within the OO paradigm (which can be considered good or bad, a matter of opinion). However while almost ...
0
votes
2answers
95 views

How can we make a UML diagram (or something similar) for a project which doesn't contains classes (like non object oriented)?

I am working on a python project and I didn't use classes but created different modules and added functions in them. Now I need to draw a diagram to describe the project/application for a paper. I ...
0
votes
1answer
201 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 = ...
23
votes
5answers
24k views

When and why to use Nested Classes?

Using Object Oriented Programming we have the power to create a class inside a class (a nested class), but I have never created a nested class in my 4 years of coding experience. What are nested ...
1
vote
2answers
1k views

Singleton pattern without static

I heard that static (in the Java sense, basically a static method is called on the class itself and not on an instance) is not True OOP. However, how would the Singleton pattern be implemented in such ...
2
votes
2answers
91 views

Angular class design dilemma

I'm trying to set up a good class diagram for my Angular application, however I have a problem figuring out how to solve the following situation: I created a base Link class that can be used anywhere ...
-1
votes
1answer
235 views

What is the programming paradigm when I just use functions in a file to organize my program?

I'm programming a telegram bot with Python and, for a number of reasons, there are no classes in the whole project, just several functions correlated to the the file where they are located. E.g., my ...
-1
votes
0answers
51 views

How exception handling is related to object oriented programming? [duplicate]

As a programmer, I have write lines of code everyday using object oriented programming concept where I used each and every concepts of OOP and during which I also deal with exception handling in Java. ...
4
votes
2answers
722 views

PHP OOP dependency injection - when is it o.k. to use the “new” statement

I was told to avoid "new" statements in classes or functions but rather create the objects from classes in the root of the program (maybe with the use of a DI-container) and then inject the objects ...
2
votes
1answer
723 views

Relations between entities in DDD

I am a beginner on DDD, working around small, simple domains in order to get my head on all the principles of design. I have this simple domain: institutions (Institution) and their available WiFi ...
6
votes
4answers
971 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 ...
12
votes
9answers
67k views

How best to learn OOP concepts/principles practically? [closed]

I wanted to learn object oriented programming language, I don't want it for any purpose just to know the whole concept of OOP. So can anyone tell me which language I should start learning?
-4
votes
1answer
143 views

File structure of object-oriented projects seems cluttered [closed]

In computer science courses at University, assignments written in OO languages such as Java had file systems similar to this: TreeNode.java BinaryTree.java Assignment1.java etc. ... In writing some ...
-1
votes
0answers
46 views

How to share/synchronize information between low level classes application-wide [closed]

We have a page-based application that is moderately large and contains multiple render views on different pages. The views are quite well encapsulated, and each have a 'tool-based' architecture where ...
6
votes
3answers
1k views

Is it poor practice to have a class implement an abstract class without adding any new fields/members/functionality?

I am writing a wrapper for a REST API and I have run into something I have never had to ask myself before. This API is for E-Commerce transactions, it has SALE and RETURN endpoints (and some other ...
1
vote
0answers
43 views

PHP: Binding PDO result values to class properties

I am new to PHP and am trying to figure out the best practice with respect to binding column values to properties in a class. The column names in the database are not ideal and I would like to extract ...
1
vote
2answers
63 views

Unit conversion of input to/output of public functions/methods

The question/s I'm working on a small scientific Python package. Many of the public methods it is going to offer will have to deal with dimensional input. A wavelength, for example, which could be ...
2
votes
3answers
285 views

Is this design with globals bad?

I designed a Snakes and Ladders game. I divided into a reasonable amount of classes and I believe I did a good job regarding the OOP design. I have one question about a decision I made for the design,...
3
votes
2answers
305 views

Should one make the database calls in the constructor or method of a class?

Take the following instance for example: CreditCardApplication class public class CreditCardApplication { public int Id { get; set; } public string FirstName { get; set; } ...
0
votes
1answer
43 views

How to associate tree nodes with other objects before they have unique identifiers

I've been thinking about a simple software design problem. Imagine I am writing a web application to edit a tree of objects. Each node of this tree has an ID property that is filled in when the node ...
3
votes
4answers
215 views

simple OOP classes right approach

At start, I have these classes in code and consequently tables in the database. Person Company Address Both Person and Company have an address. So I have to establish a relationship between them. ...
10
votes
2answers
3k views

Exceptions in DDD

I'm learning DDD and I'm thinking about throwing exceptions in certain situations. I understand that an object can not enter to a bad state so here the exceptions are fine, but in many examples ...
0
votes
6answers
2k views

How to change the state of a singleton in runtime

Consider I am going to write a simple file based logger AppLogger to be used in my apps, ideally it should be a singleton so I can call it via public class AppLogger { public static String file = ...
0
votes
1answer
71 views

Structuring PHP classes that need to return multiple objects

I am trying to plan out php class structure for an order processing project. I've used classes before but I'm still not an expert on OOP yet. I've been searching for hours and can't seem to find the ...
6
votes
2answers
2k views

Repository pattern implementation that knows nothing about the database table and column names

I've seen around the Internet and Github, implementations for the design pattern Repository that knows about database table and column names. I was think, if I want to work with the database as a ...
1
vote
3answers
270 views

Is it sometimes okay to intentionally violate the Dependency Inversion Principle?

I am doing some work to refactor a class. It currently a 'God class' and contains all different logic/operations solely in that class. One of my solutions is to extract all different parts of logic to ...
0
votes
1answer
182 views

Handling Different Parameters for Derived Classes

I'm designing an API and I ended up having a few pure abstract classes. Because of the nature of the problem that I'm solving, each derived class has to be initialized with different sets of ...
8
votes
4answers
410 views

C++ Preferred method of dealing with implementation for large templates

Typically when declaring a C++ class, it is best practice to put only the declaration in the header file and put the implementation in a source file. However, it seems that this design model does not ...
0
votes
1answer
74 views

Implementing interface segregation

I am mainly concerned about how to create concrete objects properly when implementing different interfaces. I have a resource whose variants can support different interfaces. For example, say I have ...
-1
votes
2answers
101 views

How would you design the abstraction/class(es)/component(s) of a third-party service/api used in your application?

Lets say you were designing a Twitter client for people with people could see tweets and post tweets? How would you design the twitter api abstraction? Many of the api wrappers I've seen feature an ...
1
vote
3answers
76 views

Applying Composition Over Inheritance to Page objects

I'm trying to figure out how to apply composition over inheritance to a system I'm building, and tripping up when I try to apply it to my page objects. The relevant objects are: PageFactory Page ...
1
vote
4answers
213 views

Interface with similar methods

I'm currently taking over a project that has a common pattern of interfaces like this: public interface EmailService { void sendInvitationEmail(Payload payload); void sendNotificationEmailToAdmin(...
1
vote
0answers
44 views

Extensible / Plugin Architecture in Python - overwriting methods deep in the inheritance tree?

Current situation I'm developing a test-framework in python for end-to-end tests for a large ERP application. The AUT (application under test = ERP system) is structured in modules and provides a lot ...
1
vote
2answers
179 views

UML - Identifying use cases and actors

I'm currently learning object-oriented programming and we have moved on to UML. We are learning about use cases and actors currently and we need to create a list of actors and use cases initiated by ...
0
votes
4answers
297 views

Is Template design pattern a bad practice due to inheritance?

I have been using Template Design pattern in my code for implementing CRUD procedures for different resources. There are some steps which are same for many resources and some which need some addition/...
0
votes
1answer
51 views

PHP: simple class for storing read-only data structure, array alternative

I need to share some associative data between different parts of my application with two requirements: immutability (so read-only) safety against mispelling or unavailable index inside the data ...
1
vote
1answer
108 views

Utils, Service class and Persistence Layer

I have a method in API handler which does API validation, performs business logic and then makes a call to db. Is it a good idea to move the business logic to utility class or service class? IMO the ...
0
votes
0answers
34 views

Neural Networks object creation from OOP perspective [duplicate]

Let's say that I have a class representing the Neural Network. The neural network is composed of three bigger units: a subpart_1, subpart_2 and subpart_3, being called in such a way, that the output ...
1
vote
2answers
102 views

Reading problem of object-oriented concept about the book “Object-oriented software construction 2/e”

I've been learning object-oriented concept from this book, and stuck in a specified concept in the middle of chapter 6. Because with no brief explaining beforehand, no one could understand my ...
23
votes
6answers
17k views

Are UML class diagrams adequate to design JavaScript systems?

Given that UML is oriented towards a more classic approach to object orientation, is it still usable in a reliable way to design JavaScript systems? One specific problem that I can see is that class ...
0
votes
1answer
81 views

What OOP design pattern would work best for an overseeing class connecting related objects enforced at compile-time?

The Problem I would like to create a managing "overseer" class that connects several related object groups together where any particular group is able to be easily swapped for another using C++11 ...
207
votes
15answers
183k views

Why do we need private variables?

Why do we need private variables in classes? Every book on programming I've read says this is a private variable, this is how you define it but stops there. The wording of these explanations always ...
-3
votes
5answers
148 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 ...