Questions tagged [oop]

23326 questions
1

votes
1

answer
303

Views

Scala Class body or primary constructor body

It's a very basic question. Out of curiosity, I wanted to know whether in the below code: class A(str: String) { //body here... } is it Scala Class body or primary constructor body or instance initializer body (like Java)?
boseAbhishek
-1

votes
0

answer
16

Views

How to print items of class including os('clear')?

Can somebody explain to me why the menu() function in the code below does not print the attributes of the class person while menu2() does? Thank you import os class person(): def __init__(self, name, age): self.name = name self.age = age def printAttr(self): print([self.name, self.age]) def menu(tit...
user10161844
1

votes
2

answer
122

Views

DI - How to refactor constructor with lots of dependencies

I'm fairly new to dependency injection, and I've come upon a situation where I have a class which is basically just functional programming -- one method in it (createPayment) requires 9 dependencies, and the other method (paypalApiEndpoint) only requires 1 of those dependencies: class Paypal { priva...
KayakinKoder
1

votes
1

answer
226

Views

oop php what is the best practice for database access? [closed]

I code as a hobby so i do not have a formal education on this topic so please excuse me for this question. I really have done a lot of research on this topic but wasnt able to get a clear answer. what class structure should i choose for database acess in php? class DatabaseObject and one child class...
J. Doe
1

votes
2

answer
654

Views

Override Go Method in Tests

So I have this Client struct that has a method UserByID that makes a HTTP request to an endpoint for a User. I want to unit test this function but also not make an actual HTTP request in the function c.Request. I want to stub that function with a response and error I can control. func (c Client) Use...
KA01
1

votes
1

answer
59

Views

How do you call an object which state can be completely described by its string representation?

Is there a name in the OOP world to refer to such objects? For example, in java 'Word'.toString(); Will return an output of Word. This is a string representation of the entity that exists currently in the program. Some more examples can be accomplished with other datatypes like Doubles, Integers, m...
Luis Durazo
-3

votes
2

answer
47

Views

How to Override abstract Property?

public abstract class SampleA { public abstract string PropertyA {get;set;} } How to Override abstract PropertyA ?
Nagaraj
1

votes
2

answer
67

Views

Object oriented design. What better? [closed]

I have a Printer class that should print a number and text. The number never changes for each Client class. I have more Client objects with different number values. What design is better? In the sample1 the number sends to print() method as argument, therefore all Client objects use single Print obj...
1

votes
2

answer
32

Views

Python MQTT callbacks in OOP

I'm currently trying to use the paho mqtt library in Python3 in a object oriented context. However, for some reason, the callback functions don't get called. import paho.mqtt.client as mqtt import time import logging logger = logging.getLogger('IDS_LOGGER.refining') logging.basicConfig(level=logging...
Daniel Siegel
1

votes
1

answer
68

Views

How to receive parameters in one array when passing arguments as an array to call_user_func_array()

I am sending parameters as an array in second argument but not able to receive as one array in my receiving function, I can receive but one value as one variable so if have 3 parameters I have define three variables in my receiving function. $this->params[] = 'val1'; $this->params[] = 'val2'; call_...
Mohsin
1

votes
2

answer
49

Views

Java's “Scanner” Method vs. Facade GoF Design Pattern

I'm studying design patterns to improve my programming skills. Right now, I'm exploring the facade design pattern. I may be confusing myself, but, as an example: isn't the Scanner is a facade? Note that I'm not asking what is a Facade, but trying to identify if Scanner is. Well, I declare it so I ca...
Lodi
1

votes
2

answer
41

Views

Accessing an instance variable within the `initialize` method

Given this basic class in Ruby: class TestClass def initialize(name) @name = name end end How do I then access the instance variable name directly from within the initialize method without creating a getter function? is this even possible? (i.e. using dot notation) or does the initialize method ceas...
seeker
1

votes
2

answer
76

Views

oop Check if return type is parent or child class

Suppose I have this class: public class Parent { public string Name {get; set;} } and this class, which inherits from Parent: public class Child : Parent { public string Toys {get; set;} } In some random class, I have a function that returns Parent: public class SomeClass { public Parent GetPerson()...
Cătălin Rădoi
1

votes
2

answer
37

Views

Linked list with memory leak issues

This program is acting as a template for what will be a linked list of bunny objects with unique names and colors. int Nodes::insert() { Node* new_node = (Node*) malloc(sizeof(Node)); new_node->name = getName(); new_node->prev = NULL; new_node->next = head; if (head != NULL) { head->prev = new_node...
MChess404
1

votes
1

answer
22

Views

Ensuring the absence of an __init__ function in Python

I'm writing a plugin-based application. Part of the specification for a plugin is that a plugin must not implement the __init__ method, as any initialization needs to be handled by the plugin manager, not the plugin itself. (A plugin writer would define their startup code in another method, called b...
Mikey T.K.
-1

votes
0

answer
31

Views

Why doesnt my code work twice? it executes fine the first time, but not the second

I need to make a function that moves the nth element in a singly linked list to the end of the list. I created some code that does that but it only works once if I try to do it again it moves the selected element to the end but the one that was moved previously gets deleted/dissapears. My theory is...
Matt
-2

votes
0

answer
18

Views

How to understand the given code for filtering

I am trying to understand the flow of this code. most importantly about the Builder $builder. Also how the code is working and sql query is being made. the code is in this link. https://appdividend.com/2018/05/03/how-to-create-filters-in-laravel/ ps. The description is given in the site itself. But...
TeachMe
0

votes
0

answer
13

Views

What are some real-time examples of OOPs concepts used in the automation framework using selenium with java?

I have been working as Manual tester for a quite sometime and also worked in few automation projects using Selenium with Java. Recently, I was attending few Automation interviews as I wanted to shift to Automation using Selenium with Java. I faced following question in the interview 'What OOPs conc...
Sri
0

votes
0

answer
3

Views

Any walk around to use polymorphism and virtual functions in CUDA kernels?

I implemented a simple CPU path tracer in OOP fashion, and now trying to port it into CUDA to speedup, and hit the problem that CUDA kernels doesn't take derived classes of virtual base classes. I'd like to know in my specific case what would be the best option to make it happen. The simplified proj...
quanke0801
1

votes
3

answer
175

Views

Issue related to concept of abstraction in OOPs

I was reading OOPs Concepts from internet using articles. In one of article, I have read following about abstraction: If we have a method named 'CalculatePrice' inside the 'Billing' class, we are not concerned about the calculations inside the 'CalculatePrice' method. We just pass the necessary para...
ghanshyam.mirani
1

votes
2

answer
1.9k

Views

Passing Child class as parameter

I have a base class public abstract class BaseClass { public DateTime CreateTime { get; set; } public string CreateUser { get; set; } } And few child classes which derive from Base Class public class Child1 : BaseClass { } public class Child2 : BaseClass { } For the Client which uses these child cl...
s-a-n
1

votes
1

answer
58

Views

Method Overloading for Null Argument by passing 0 and null

I have seen questions on Stack Overflow about a method overloading for null argument but didn't solve my confusion and I tried something different which was not discussed in there answers that's why asking this question. I want the reason when I pass 'null' it executes the function whose argument t...
AmeeQ
1

votes
1

answer
63

Views

Abstract builder constructing immutable object

I have following code implementing abstract builder (as in effective java book): interface I { I ret(); } abstract class A implements I { private String s = ''; A(Builder b) { s = b.s; } @Override public I ret() { String s = 'some new string from calc.'; //HERE I NEED TO CONSTRUCT class B //THIS IS...
Bojan Vukasovic
1

votes
3

answer
59

Views

Creating global variable or creating instance inside of function

It is not a coding question but related to coding concept. I have a service class with some methods and also this class have following 2 private method for url parse and validation process. private boolean isUrlFormatValid(String url) { Pattern pattern = Pattern.compile('^(https?:\\/\\/)?(www\\.)?([...
abidinberkay
1

votes
1

answer
71

Views

Achieve Open-Closed Principle (SOLID) Using Interface

I have multiple types of payment options (Stripe, Paypal, PayUMoney etc.). I want to create seperate class for each payment type and an Payment Interface to be implemented by those classes like this, interface PaymentInterface { public function payment($params); } class Stripe implements PaymentInte...
Muhaimenul Islam
1

votes
2

answer
23

Views

Force usage of specialized subclass

I am trying to force the usage of a more specialized class when a superclass is called with certain parameters. Concretely, I have a Monomial class (whose __init__ takes the coefficient and the power) and a Constant class. I wish that whenever Monomial is called with power=0, a Constant instance is...
Anakhand
1

votes
2

answer
112

Views

Design pattern to enrich a class with new features [closed]

I have implemented a series of classes to manage search / detail page with JSF and PrimeFaces. More in detail, I've created an abstract class SearchDetailView in order to centralize common functionality for Search/Detail page. In short, I've a class MyView that extends the base SearchDetailView. Now...
Alessandro
1

votes
4

answer
58

Views

python - confusion how the “as” keyword works in an except statement

I have been trying to understand in general how the 'as' keyword in python works so far and have learnt 3 cases for it Case 1: import foo as bar Case 2: with foo() as bar: Case 3: except Exception as e: I understand how the first 2 cases work, case 1 works assigning a package name to a different nam...
NightShade
1

votes
2

answer
36

Views

Bundle specific exception listener

Lets say I have 3 different bundles. I am adding to event listeners to each bundle. When there is any exception in Bundle1, then Bundle2 and Bundle3 should not listen it. I have tested it adding to each bundle eventlistener but when there is any error in Bundle2 then Bundle1 will listen try to handl...
MRustamzade
1

votes
2

answer
65

Views

How can one access a base class method using base class object once it has been overwritten?

This question might be applicable to all/most Object-oriented programming languages but I am only concerned about the SystemVerilog side. Polymorphism, I thought I understood, until I was talking to a colleague the other day and this came and I realised that I don't know how this can be done. Follow...
Timothy Grant
1

votes
4

answer
49

Views

Why overriden toString is not called while printing null reference [duplicate]

This question already has an answer here: Why does null reference print as “null” 3 answers I Know while printing the object, java calls the toString() method internally. But after overriding the toString() method, Java not calling the overriden toString() method for the null reference. Please...
parthiban
1

votes
1

answer
64

Views

using Map vs Enum

I need to keep a mapping which finds some properties given a String. For an example like below, I need to get possible colors for an animal given the description for that animal. I have 'An animal with four legs' - not 'CAT' - and need to find BROWN and GREY. Keeping this in an enum makes code more...
canan
1

votes
3

answer
3.5k

Views

What is virtual polymorphism?

I know about polymorphism and the keyword virtual in C#.net, but i don't know what is Virtual polymorphism, I was asked this question in a interview yesterday. Thank you
Vamsi
0

votes
2

answer
49

Views

Can i make a class that behave like a primitive type?

I made a Point class to manage xy coordinate (I know some java default packages already have some Point object that behave in a similar way, I use it as a lazy alternative and this is an example, please dont mind it ^^). Before using it I was using the int primitive type. thing is, when passing a cl...
The Teluri
1

votes
0

answer
88

Views

C#, Get class properties

I have the following class structure: class structure The user can select to work with SystemA or SystemB. The following code is from the class that creates the main object: public class MainViewModel() { var project = new Project(); project.PropAList = new List(); project.PropAList.Add(new SystemB(...
gr1d3r
1

votes
0

answer
278

Views

How to remove annotations of a variable in a child class

Let us say that we have a class from API which has some fields, of which some are made mandatory using @NotNull annotation, like below: class SomeAPIClass { private String field1; private String field2; @NotNull public String getField1() { return field1; } public String getField2() { return field2;...
Rupesh
1

votes
1

answer
36

Views

If I extend a class in python, how to automatically return the result as the new class?

Here is a simple example: import pandas as pd class test_pd(pd.DataFrame): def __init__(self): super().__init__() def my_copy(self): return self.copy() if __name__=='__main__': a = test_pd() #a has a.my_copy() b = a.my_copy() #b does not have b.my_copy() I would like the test_pd.my_copy() function t...
fnosdy
1

votes
1

answer
51

Views

Class Decorators Excercise in Python

I'm learning Python from the video course Python Programming Language by David Beazley. I got stuck in this program where the author tried to decorate the Holding class by @typed. Unfortunately, although I believe I copied the code verbatim, it didn't seem to work according to plan. I duplicated the...
Jeremy Chen
1

votes
1

answer
147

Views

Using S3 Constructors in R

I was looking at some code earlier today (https://www.r-bloggers.com/building-your-own-blockchain-in-r/) where someone was defining S3 functions in a way that I'd never seen before and liked the visual style, but have never seen it anywhere else in R code and wanted to figure out why. They defined a...
Alex Gold
1

votes
1

answer
53

Views

Trying to get property of non-object using php oops concept

I am trying to retrieve the data from database using OO-PHP Here is my code user.php database.php public function query($sql){ /*$result = mysqli_query($this->connection,$sql);*/ $result = $this->connection->query($sql); $this->confirm_query($result); return $result; } index.php $users = User::find_...
Sanam Rohit

View additional questions