Questions tagged [oop]

Object-oriented programming is a programming paradigm using "objects": an encapsulation consisting of data fields and methods together with their interactions.

Filter by
Sorted by
Tagged with
0 votes
1 answer
10 views

Kotlin: how to have abstract values as default arguments for abstract functions?

I have a sealed class that represents my screen states, and the different screen states are data classes, since I want to be able to copy them while changing just one value. Unfortunately Kotlin doesn'...
Felipe Ribeiro R. Magalhaes's user avatar
-1 votes
0 answers
27 views

Why Derive class function default parameters not taken by compiler [duplicate]

I have write the code that its perform the virtual functionality and once i called the Derived call function than its called the Derived class function but its take default parameters of Base class #...
Jigar Patel's user avatar
0 votes
0 answers
7 views

Does it make sense to apply dependency inversion if it requires instantiating a dependency with default values to update them later?

In this example a Database gets a get_image method which returns an Image. To respect the DIP the example include all the necessary interfaces. import abc class ImageInterface(abc.ABC): "&...
amarion's user avatar
  • 353
0 votes
0 answers
8 views

Parametrize schema when creating DB tables with sqlalchemy

I have a module db_models.py where I define my tables like so: from sqlalchemy import Column, String, Date from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() class ...
Sergey Zakharov's user avatar
-2 votes
1 answer
40 views

Automated and scalable approach to store each dictionary item into class (instance) attributes with same keys and values?

I have a dictionary input_dict={'foo1':3, 'foo2':6} and I want to store its contents in an instance of class matClass such that mat.foo1=3, mat.foo2=6, etc... I need this process to be automated since ...
Carlo's user avatar
  • 185
1 vote
1 answer
22 views

Passing in private attributes into a utility function

I have 3 classes with a merge operation that does identical operations with different arguments. Here's the skeleton code of what I currently do: class FirstClass: def __init__(self): # define ...
roulette01's user avatar
  • 1,990
-3 votes
0 answers
46 views

I want to make a generic function that return back the generic in C++ [closed]

I want to make a generic function(like in c#) that return back the generic in C++ my script have a .cpp and a header file i don't know how is need to look in the header. this is my false try: //.h //...
oscar7070's user avatar
0 votes
1 answer
33 views

Casting types in python __init__

I have a python class where one of the attributes should be a Decimal. Is there any potential issue with casting within the init method (example a) or is it simply a design choice? Is there a reason ...
peaky76's user avatar
  • 117
0 votes
2 answers
46 views

SystemVerilog inheritance, aggregated classes and parent function call

I have a problem with super.func() call in SV. I have three main classes: class_C extends class_B; class_B extends class_A; class_A; And I have three configuration (aggregate) classes: inner_C extends ...
Андрей Ефимов's user avatar
2 votes
2 answers
53 views

Python Inheritance and Overloading Problems

I have an parent class, that has holds some kind of lists and has functions to add objects to these lists. It is rather an Abstract class, which i will never instanciate, but only use as a blueprint ...
julianmueller's user avatar
0 votes
0 answers
15 views

Is exposing a collection through a getter an anti pattern? [closed]

Is exposing a collection (List, Set) through a getter an anti-pattern? I used to think so, and I still believe assigning the collection in the parameter to the field in the setter directly is not a ...
tbeernot's user avatar
  • 2,473
-1 votes
0 answers
34 views

OOP in Distributed data processing like pyspark [closed]

I have a doubt so I need your advice and opinion on below query.  Does OOP is a good chioce of programming for distributed data processing ? like Pysaprk in Databricks platform ? If not then what it ...
Atanu chatterjee's user avatar
-1 votes
1 answer
15 views

Problem with adding my class into XamlPage

Have a little problem with connecting my class to xamlpage... VS text me that program can't see namespace but i have another class at this folder which one is working normaly and i want to show you ...
 XedDevil 's user avatar
0 votes
0 answers
12 views

I want to stop specific customer group to buy not more than two products and also stop on specific amount of cart in magento2

I want to stop specific customer group from buying not more than two products. Also I need to stop them on specific amount in cart. Is that possible if yes then what is the best possible way to do ...
syed usama's user avatar
0 votes
1 answer
8 views

Is it necessary to return the same object in methods with fluent interface

in some sources such as the original article of Martin Fowler aren't written that methods would return the same object, and methods in examples return different objects but in some sources(newer) such ...
user502233's user avatar
0 votes
0 answers
24 views

What are interfaces in javascript? [duplicate]

mdn mentions EventTarget interface and several other interfaces. so what do it exactly means by interface? Even when I am trying to use interface keyword in js it is showing error? And what kind of ...
Vikas Rana's user avatar
0 votes
0 answers
19 views

Python runtime for the code significantly different depending upon where the recursion function is placed

I am trying to solve a leetcode problem. My solution gives markedly different results depending upon the kind of construction I have of the code. The only way to explain this is by giving you the ...
figs_and_nuts's user avatar
0 votes
0 answers
32 views

Uncaught Error: Class "B" not found. This error giving while using __toString method in php [duplicate]

Giving error while this code applied Error: Fatal error: Uncaught Error: Class "B" not found in D:\laragon\www\test2\collect.php:6 Stack trace: #0 {main} thrown in D:\laragon\www\test2\...
Developer Unified Infotech's user avatar
0 votes
0 answers
31 views

Allowing deepcopy for a C++ object that has vector of pointers to another object in pybind11

I have two classes defined in C++: class Pet { public: Pet(std::string &name) : name(name) {} void set_name(std::string &name_) { name = name_;} std::string &get_name () { ...
sodiumnitrate's user avatar
-1 votes
0 answers
31 views

How to expand on C++ classes on python side (pybind11)

I have a class defined in C++. I want to be able to add more methods to this class, but on the python side, as I'll be utilizing some python libraries. If I had (using a version of the example in ...
sodiumnitrate's user avatar
1 vote
2 answers
23 views

How to Create Two Similar Methods in the Business Layer of a Structured Architecture with Minimal Redundancy?

The structure of my application is layered. The GUI is handled by Controllers, the Controllers each have a Service (which is responsible for business logic). For context, when a button is pressed, ...
Kudor's user avatar
  • 39
-2 votes
0 answers
49 views

Returning a const value by reference works - why? [duplicate]

const int& check(int x) { return 2 * x; } int main() { const int& something = check(3); // First option int something2 = check(5); // Second option cout << ...
Zig302's user avatar
  • 33
-4 votes
0 answers
24 views

how to invoke __init__ of the parent class in Python? [duplicate]

class A: def __init__(self, n='Rahul'): self.name = n class B(A): def __init__(self, roll): self.roll = roll object = B(23) print(object.name) Python program to ...
Raju Roy's user avatar
0 votes
0 answers
13 views

Regarding what to call class methods of this form

I have never thought to figure this out, but often I see methods such as these int Foo::Bar(int x) { return baz->Bar(x); // baz is an instance of another class stored as a member in Foo. } in ...
Scene's user avatar
  • 489
0 votes
2 answers
20 views

Python inheritance : change parent attribute in child class and use it in a method in parent class

I have a parent class that has an attribute kids=2. The attribute changes in the child class. The parent class has a method that uses that attribute, I want the method to give different results under ...
Sikafica 's user avatar
1 vote
1 answer
24 views

The different between fluent interface and method cascading implemented by method chaining [duplicate]

When I read about it on Wikipedia, it seemed to me that these two are almost the same, but the same article says that they differ not only in the use of DSL. Note that a "fluent interface" ...
user502233's user avatar
-1 votes
1 answer
38 views

How to change const variable to variable in class property?

I have a class name GetCampaigns. It contains private const CUSTOMER_ID as a class property. I want to assign global variable value to this property. GetCampaigns.php class GetCampaigns { private ...
God Uncle's user avatar
-2 votes
2 answers
65 views

For a class, how should I decide whether to pass a variable as a parameter, or set as an instance or global variable? [closed]

I'm learning OOP, and I'm very confused about how to best handle variables inside/outside classes. For instance, let's say I want to access a certain variable within a specific method of a class. ...
Danny_webb's user avatar
0 votes
0 answers
22 views

How to combine multiple languages in one website using flask? [closed]

New here, I am a python full stack student, in the 2nd month of a 6-7 months course. I am super excited because I wanted to learn programming a long time ago, but didn’t proceed to chase my dream. I ...
M.S's user avatar
  • 1
-3 votes
0 answers
30 views

What is best practice to organize/categorize methods within a class? [closed]

I'm working on sort of a text based choose your own adventure style game where as you progress you will run into scenarios where you will be faced with anywhere from 2-4 choices. There will be ...
birchwoody's user avatar
0 votes
1 answer
30 views

Accessing object generated within a list

So i've been practicing with OOP in python and decided to take a program i wrote before and update it using OOP methodology. Basically it's a game where it will ask you how many players you are ...
Charlie Jandura's user avatar
-2 votes
0 answers
53 views

How can I wrap OpenGL pointers to C++ objects? [duplicate]

I am trying to build a little OpenGL framework in C++ and encounter an issue with my wrapper classes: I initialise the pointers with zero when starting the application because OpenGL is not yet ...
julcs's user avatar
  • 29
-1 votes
1 answer
21 views

Patches not drawing themselves on my figure [closed]

I'm working on a program to animate gravitating celestial bodies on a plane using matplotlib. I am building it with an OOP approach, since I have created an Animation class to handle all the ...
McCiocco's user avatar
0 votes
1 answer
40 views

Canvas: Two balls having the same color

I'm trying to learn canvas and I'm at a point that I want to spawn balls of different colors. The problem is when I instantiate a new object called ball2 it seems that ball doesn't retain its original ...
G R's user avatar
  • 3
2 votes
1 answer
36 views

Updating deeply nested fields that are immutable

I have a heavily nested class structure that does not have setters. @Value @Builder(toBuilder = true) public class ClassA { private String fieldA; private ClassB classB; } @Value @Builder(...
user1692342's user avatar
  • 5,049
1 vote
1 answer
22 views

How do you approach OO Design and OO Programming with GameObject and Components in UPBGE?

How do you approach OOD with GameObject and Components? I’m trying to better understand things in a deeper sense. I usually have something like: class Player(KX_GameObject) and then I have several ...
Davi Silveira's user avatar
-2 votes
0 answers
38 views

how should a python program be ran? [closed]

I'm wondering how a program should be ran inside the if __name__ == "__main__": block. Should it be like this: if __name__ == "__main__": objectInstance = Instance() ...
Nicke7117's user avatar
  • 183
0 votes
0 answers
37 views

I'm having errors "Workspace is closed" opening my Eclipse for the first time

When I opened Eclipse, it says that "workspace is closed", and doesn't open, every single time. It has problems intializing external folders, and workspace is closed. I posted pictures to ...
thegreatcodingwizard7's user avatar
1 vote
1 answer
36 views

How to pass a class in interface definition

I create BaseService with common functions for all entities which inherit the base object, public class Committee : BaseObject: public interface IBaseService<T> where T : BaseObject { } public ...
Dr. MAF's user avatar
  • 1,865
0 votes
2 answers
42 views

C++ refactor common method/logic without polluting interface

I have an interface: class FooInterface { virtual void Method1(bool method) = 0; }; I have multiple derived classes which implement this interface which all have common logic/method [Method1]: ...
Matt Stokes's user avatar
  • 4,620
1 vote
0 answers
23 views

Where to put factories that depend on the application layer?

I am a frontend developer (currently working with Vue and TS), and I have been searching for better organization of the frontend code and recently I got to know DDD a bit. I know DDD is mostly used ...
Bernardo Benini Fantin's user avatar
-2 votes
1 answer
29 views

Python equivalent of @ElementCollection @Enumerated(EnumType.ORDINAL)

I am unable to understand what @ElementCollection does in this code. I need to write its Python equivalent. package project.models; import lombok.Data; import lombok.Getter; import lombok.Setter; ...
Shailaputri's user avatar
-5 votes
0 answers
45 views

Unidentified characters when I try to write an object to a file [closed]

When I write an object to a file, I always get a number of unindentified characters. fstream fout; fout.open("data.txt", std::ios::out); When I try to read from the file, the the numbers ...
lk9895's user avatar
  • 1
0 votes
1 answer
53 views

Java: can I know which class was passed?

I have an interface Interface I {} I have 2 classes implementing I. Class A implements I {} Class B implements I {} Now, I have a new class which takes the interface as member. Class C { I i; } ...
user4202236's user avatar
0 votes
0 answers
60 views

Why "Base Constructor" function has called twice? [duplicate]

Please take a look on the following example: class Base { public: Base() { cout<<"Base Constructor\n"; } Base(const Base& Obj) { cout<<&...
Jayesh's user avatar
  • 4,793
-3 votes
0 answers
35 views

Alternatives to creating a static list in every subclass

I'm trying to give each subclass of my superclass a list of all of it's own instances. My initial plan was to give the superclass a static list for each of the subclasses to inherit their own copy of, ...
ZeusLarp's user avatar
-2 votes
0 answers
35 views

Abstract class, Interface, or Util? [closed]

what is a good way to implement classes for this use case? I want to calculate something two different ways. But, there are some methods that are similar between the two that I want to avoid ...
N.A's user avatar
  • 131
1 vote
0 answers
89 views

How can the C++ data-oriented design achieve polymorphism without using virtual functions?

I have found that data-oriented programming is a good way to bridge the gap between object-oriented programming and functional programming. Data-oriented design uses data instead of objects: https://...
Nathan Doromal's user avatar
0 votes
0 answers
10 views

How to structure a cart with cart products object

I am new to DDD and I am having trouble structuring an object. I have a cart, where I can add products to it. Each product has some properties like image, title, price, etc. Whenever a product is ...
Bernardo Benini Fantin's user avatar
0 votes
0 answers
25 views

Base class undefined. How would I go about fixing this issue?

I want to create the object "keyEventsInstance" on the stack as a private member of the class "MultiLauncher" (see MultiLauncher.h) and then have keyEvents::processKey(uint key) ...
LondonNight's user avatar

1
2 3 4 5
1238