62,265 questions
0
votes
1
answer
91
views
Troubleshooting creating a Word document in an Excel vba Class module
For various reasons, I am currently refactoring some code to a more OOP approach. I am immediately having the following problem: When the Create method of the class module creates the new Word ...
Best practices
0
votes
1
replies
35
views
In LLD interviews, should class design be driven by domain modeling, database structure, or API/use-case access patterns?
I am trying to understand how Low-Level Design (LLD) should be approached in interviews.
My confusion is that the design changes depending on the perspective I start with.
For example, if I design ...
-4
votes
0
answers
83
views
Python updating all instances of an object in a list instead of a single instance [closed]
I'm working on a text-based RPG to improve my coding skills. To better differentiate between enemies with the same name in battle, I feed a list of enemies into the function below which returns the ...
0
votes
2
answers
57
views
Why do I get the error " "vector_one.x" is not a valid function argument name" when calling an object of a class? [closed]
I am making a vector utility class for a ray tracer and was unsure of where I went wrong with my code below; it returns this error message:
ERROR: syntax: "vector_one.x" is not a valid ...
Advice
1
vote
12
replies
162
views
Should I focus on coding exercises or building projects to learn C++?
I am a begineer and i want to learn c++ by doing projects please suggest me any project that i can do to increase my experience of c++
my old projects are:
hang man game
bank management system
has ...
0
votes
3
answers
149
views
How to refactor multiple if-elif statements into a Strategy pattern in Python? [closed]
The Problem: I am building a simple data processing tool. Depending on the file format (JSON, XML, or CSV), I need to apply different parsing logic. Currently, I’m using a long chain of if-elif ...
4
votes
2
answers
157
views
Get multiple indexes of an array at once, for comparison
I am working on a Tic_Tac_Toe project. I have an object (gameBoard) that contains an array, then I have another object that i want to create a player from to play on the board, then I have a function ...
Advice
2
votes
8
replies
148
views
C# Dependency Injection Without Objects?
When writing C# applications, it often feels like we’re encouraged to make methods instance-based even when they would naturally be static. Of course C# is an OOP-first language and patterns like ...
Advice
0
votes
10
replies
206
views
question regarding parent and child class
Given a class Child which is derived from class Parent. When creating an object from class Parent, select the correct type for the variable dan which will be assigned the reference to the Parent ...
Best practices
0
votes
3
replies
54
views
Class inheritence vs one class being element of the another
Suppose we have two classes A_class and B_class. We want to connect them in a way that allows to access methods and data of B_class from A_class .
We can do it through inheritance:
class A_class : ...
Best practices
0
votes
6
replies
113
views
How should toString methods be formatted
I lately learned about the toString method and its uses.
From what I've been taught, the toString method is used as a concise representation of an object as a string of characters, usually used as a ...
0
votes
1
answer
115
views
While implementing custom stack I got type 'int' must be a reference type in order to use it as parameter 'T' in the generic type or method 'Stack<T>' [closed]
I am getting this error while implementing a stack by myself.
Here is my code
interface IStack<T> where T : class
{
void Push(T item);
T Pop();
T Peek();
bool IsEmpty { get; }
...
Advice
2
votes
4
replies
143
views
How do I modify Enemy class to chase the player in an object-oriented programming JavaScript game?
I'm trying to create a game in HTML, CSS, and JavaScript. I started following the tutorial by FreeCodeCamp: https://www.youtube.com/watch?v=7BHs1BzA4fs. The tutorial was on a side-scrolling game(...
Best practices
0
votes
3
replies
137
views
Is using Singleton pattern in Python viable for global Configuration object?
I've read quite a bit on SO and elsewhere on Singleton being anti-pattern (hard to test, thread unsafe etc), e.g.: https://www.michaelsafyan.com/tech/design/patterns/singleton
However, there still ...
Advice
0
votes
10
replies
268
views
Are Claude's advices good practices that I should use?
I am still a beginner, and I am trying to understand what is a good practice and what is not. Saw a YouTube video on a little project about making a turn-based game in C# in the Console while also ...
Best practices
0
votes
5
replies
107
views
Is it good design to use dynamic cast?
I am trying to implement password manager on Java right now. I am implementing the vault. I have VaultEntry and VaultFolder classes. VaultEntry has fields id, parentId, name, username, email, password ...
2
votes
1
answer
182
views
Is this design of operator== correct?
I have a hierarchy of classes which should compare for equality by the following rules:
objects of different classes are not equal;
objects of the same class are compared using logic specific to ...
Advice
0
votes
2
replies
147
views
Getters and Setters in Python (Dataclasses)
I'm learning for my Introductory Programming Course in uni and I don't have an overview over the different cases when it comes to Setters and Getters and the slides are not quite helpful.
So for ...
Advice
0
votes
11
replies
207
views
When to use standalone functions in C++?
I am a beginner C++ programer and I am trying to make a very simple random number generator for my program.
I started doing this by creating a struct in a header file but I am wondering if this is a ...
Advice
0
votes
5
replies
101
views
Python class, attribute
I'm struggling with the following code:
class Esempio():
def __init__(self, a, b, c):
self.a = a
self._b = b
self.__c = c
def __str__(self):
return f"a={...
1
vote
1
answer
97
views
Why is this type-bound procedure causing a slow-down?
I am working on some simulation code in Fortran. Part of that are potential cells that induce velocity.
Here is the definition for the cell type:
type CELL
doubleprecision :: xmin,ymin,...
-3
votes
1
answer
120
views
What are the differences between setattr and __set__? [closed]
I only know that setattr is built-in function that allows us to change value of attribute of object and __set__ is descriptor. This is all knowledge. What are the differences?
2
votes
3
answers
260
views
Is it possible to eliminate the this pointer in a singleton?
This question is about the singleton pattern in modern C++ and one of its limitations in particular.
I can implement the singleton pattern like this:
class Logger
{
public:
static Logger& ...
0
votes
1
answer
99
views
How to fix mutable objects inside a copy of IReadOnly copy of a list
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MonoGame.Extended.Graphics;
namespace GameCore.Core;
#...
0
votes
1
answer
76
views
How does super() initialize properties on a subclass instance in JavaScript?
I’m learning Object-Oriented Programming in JavaScript and got confused by the following code:
class Animal {
constructor(lg) {
this.legs = lg;
}
}
class Dog extends Animal {
constructor() {...
2
votes
1
answer
638
views
How does attribute access (.) actually work internally?
When I write obj.attribute in Python, what exactly is the sequence of operations and lookups that Python performs to resolve this attribute?
I want to know when and how methods like __getattribute__ ...
Best practices
0
votes
1
replies
95
views
Design pattern for keeping two mutable object views in sync
I have been working on a game engine and have come upon a design that is challenging for me to implement. In particular, I need two mutable objects, that themselves contain mutable properties, to ...
4
votes
1
answer
139
views
How to access class methods from the class variables in python
I am processing excel sheets with pandas, and here's an abbreviation of what I have so far:
class DataLoader:
"""
Loads excel sheets & convert them into CSV
""&...
Advice
1
vote
6
replies
108
views
Can an abstract class enforce trait usage?
I know we can have:
<?php
abstract class ExtendMe{
abstract public function implementMe(){}
}
Can we enforce trait usage?
<?php
trait MyTrait{}
abstract class ExtendMe{
abstract use ...
Best practices
1
vote
1
replies
38
views
What are the pros and cons of a terse property/method-syntax?
In designing a language from scratch, should methods use a self variable to access properties and other methods? Or should they imply their target with .prop? Or should they treat properties as local ...
Best practices
0
votes
0
replies
37
views
Implementing sdk-agnostic callbacks in fragments
My question is not Android specific, it is rather more design-specific.
Previously I had a BaseFragment that many child fragments were derived from. base fragment had objects of mapbox map to handle ...
0
votes
2
answers
130
views
How to break circular dependency in Python class when trying to separate a simple wrapper class from a heavier implementation?
I am trying to build a small scale deep learning framework. I defined my tensor class as follows
class Tensor:
__slots__ = (
"_backend",
"_data",
"...
0
votes
1
answer
104
views
Java OOP association SQL equivalent
I have two classes: Student and Group.
Student attributes:
private String registrationNumber;
private String firstName;
private String lastName;
private Date dateOfBirth;
private String password;
...
Best practices
0
votes
3
replies
78
views
Most efficient way to manage the lifecycle of HttpClient in many wrapper classes?
Our application is somewhat of a middleman that transforms data from numerous APIs. Initially to simplify things, we wrote a bunch of specific clients which wrap an instance of HttpClient created in ...
0
votes
1
answer
88
views
Python function not accepting state variables [closed]
import Vector
class Ball:
radius: float
color: str
position: Vector.Vector
velocity: Vector.Vector
acceleration: Vector.Vector
def __init__(self, radius, color,position, ...
Best practices
2
votes
4
replies
90
views
Injecting delegates vs object instances in a large complex project
This question is about when to use and inject delegates vs intantiating objects. Say I want to model a card game, I might want to inject the behavior for building the deck and shuffling. Since these ...
Best practices
0
votes
3
replies
60
views
How should I structure NestJS services when one endpoint needs to update multiple entities (e.g., InvestorProfile and TaxProfile)?
I’m working on a NestJS + TypeORM backend and ran into an architectural question as my codebase evolved.
Initially, I had a simple setup:
InvestorProfileController handles PATCH /investor-profile
...
Advice
2
votes
4
replies
142
views
How do you use set() on PHP arrays?
When using setters/getters on arrays, does your set() override the entire array or just the key? What is the accepted or best practice for this?
Would you use set() for something like this or would ...
1
vote
1
answer
99
views
Type-bound procedure for parameterized derived type
Could you tell me how to write type-bound procedures for parameterized types?
For example:
module parameters
type :: sinx (kind)
integer, kind :: kind=4
real(kind) :: x
contains
procedure,...
-2
votes
3
answers
210
views
Python function change behaviour depending on type of argument
I'm playing around with OOP in Python, and I have something like this:
class Person:
def __init__(self,name, age):
self.name = name
self.age = age
self.hobbies = []
...
-1
votes
2
answers
168
views
C++ design pattern for connecting templated and non-templated classes efficiently
I complete the implementation of a VM (ALU part) by adding operations to a Coprocessor. In this sense, I'm looking for a C++ design.
Through a template, the VM is instantiated in 2 ways : A first ...
2
votes
6
answers
161
views
How do I find out the type of items in a generic type collection?
I want to write a method that converts a collection of generic type elements into a human-readable string. This method should also work with nested collections. I haven't found a better approach than ...
0
votes
1
answer
87
views
In three-layer architecture, what do layer dependencies start to look like when OOP objects are involved in the Business layer?
As a coding test I've been tasked with developing a toy three-layer architecture DBMS project, involving OOP principles. The three-layer stuff isn't strictly my background so I've been trying to study ...
0
votes
1
answer
209
views
Organize the mapping of class properties to render the list of plain text first, and embed the corresponding image in the existing list
An exception occurred while iterating over the results of a query for context type 'MyProject.Data.SQLServer.SQLServerContext'.
System.InvalidOperationException: The required column 'img' was not ...
-4
votes
4
answers
173
views
How to update string attributes to object instances if they exist [closed]
I'm trying to use a for loop to iterate through a set of objects, check if those objects store string data (specifically their 'Pokemon.evolution' variable) which is the same as a the name of one of ...
0
votes
0
answers
39
views
Indesign JS : Create a class or an object that can make instances of, with unique internal values?
Is this possible? How?
Basically I want to create a class or an 'blue print' object with properties that can hold individual values?
How would I write a 'blue print' that has property of color, name ...
0
votes
1
answer
69
views
What are the "set of values" for a user-defined type (UDT) in OOP languages?
I’m a PHP programmer looking to deepen my theoretical understanding of computer science concepts, specifically Abstract Data Types (ADTs) in the context of object-oriented programming (OOP).
And my ...
3
votes
2
answers
116
views
How to write a constructor in F# of a class derived from an abstract class?
I have in an F# an abstract class and some derived classes. When instantiating derived classes, I would like to initialize a mutable property defined in the abstract class in the respective ...
0
votes
1
answer
71
views
How can I forbid method redefenition in TCL OO class?
I would like that method redefenition would result in failure and script execution stop. Like any other common error.
In the following example I want to see that method print cannot be redefined.
oo::...
0
votes
2
answers
65
views
Modular approach to dynamically extending class behavior in JavaScript without modifying the original class
I'm trying to create independent modules in JavaScript where I can add new functionality without modifying the original class.
My simplified version:
class adminMenu extends contextMenu {
...