Object-oriented programming is a programming paradigm using "objects": data structures consisting of data fields and methods together with their interactions.
0
votes
0answers
16 views
What is the right way to organize class contents?
While I was designing a bunch of classes, I found myself wondering if there is a standard for where to place these relative to each other:
private $property
public $property
public static $property
...
0
votes
1answer
19 views
Class-wide object instantiated from constructor
With someAPI in the following, it requires credentials that I would like to assign dynamically in the constructor. Then I would like to use someAPI throughout the class. Is that possible with ...
0
votes
0answers
22 views
OOP Problems - Derived Class
I am trying to figure out an undefined reference to Class::Function(). The project is one that I've seen a few responses for and I have looked at the responsesfor others and it appears that the code ...
-1
votes
5answers
64 views
Abstraction in OOPs
I have come across few definitions over the years, and have never able to clearly understand what abstraction is.
I have understood the 3 main concepts of Oops but have had difficulties with this ...
-1
votes
0answers
22 views
2 functions call from same class not working
I wrote a class, and inside it two functions, when I call both functions I get errors:
This is the code:
$password = $_REQUEST['passReg'];
$email = $_REQUEST['emailReg'];
$user = ...
-1
votes
0answers
8 views
unable to excecute functions and headers not working
im not really sure what might be wrong with this one, to start off i have the class client which is the action on every form , and it calls the clases to excecute the functions inside a class,i took ...
2
votes
3answers
37 views
How to get variables from a extended class into its parent class
I'm trying to make a table making class, but for different pages I need different kinds of variables. I want to do this by having the general layout in the parent class and then put all the specifics ...
0
votes
0answers
7 views
Using JNA, how do I create a 'C++ class' and pass it to a C++ function,?
I need to call a proprietary DLL function with the following prototype (simplified for clarity):
int J_Image_OpenStream(J_IMG_CALLBACK_OBJECT obj, J_IMG_CALLBACK_FUNCTION function);
The type ...
0
votes
3answers
52 views
Killing the application manually when catching a exception?
I have a connection class wich initializes the database credentials when i __construct it.
Whenever this fails, it throws an exception that the credentials cant be set because the file is empty or ...
-3
votes
1answer
53 views
What is the different between these object initializations?
#include <iostream>
#include <string>
class MyClass{
public:
MyClass(){
std::cout << "Called Constructer A \n";
}
MyClass(int n){
std::cout << ...
0
votes
1answer
42 views
Prevent Instantation of class outside of this class
I use Entity Framework and the generated classes for the DbContext. This classes are generated and every change i do is overwritten the next time i refresh my DbContext.
Now i override this class ...
0
votes
1answer
20 views
call_user_func with $this as a parameter in php 5.4
I need to call a dynamic function and send the current object as reference in the said function.
In PHP 5.3 this works, as opposed to PHP 5.4:
$value = call_user_func("MyFunction", $value, $row, ...
-1
votes
3answers
29 views
PHP Object Visibility and Inheritance
I'm reading this tutorial about PHP Classes. I haven really fully understand it, can anyone help me out here?
I came across this class
<?php
class foo{
private $_var;
...
0
votes
2answers
33 views
Is it still an observer pattern without the interfaces for observer and subject? Here is an example I'm not sure about
I'm learning object oriented design patterns, but don't see why this is not the observer pattern if I only have concrete listener and subjects. In my practice example I have created a DMV office ...
-1
votes
1answer
58 views
C++ storing an abstract object in an array
I have been trying to pass object of an abstract class as by reference but it clearly gives error when I try to store this objects in an array of pointers with the same data type. Can anyone please ...
1
vote
3answers
22 views
PHP static class variables still holding values after initial instantiation
I have:
class A {
static $instances = 0;
public $instance;
public function __construct() {
$this->instance = ++self::$instances;
}
}
$a = new A();
$b = new A();
echo ...
0
votes
1answer
40 views
Polymporphism, how to avoid type casting?
I'm sorry for the long question but bare with me, I tried to explain my problem to be as understandable as possible. If you believe it can be more concise feel free to edit it.
I have a client-server ...
0
votes
0answers
29 views
C++ linking header files and class files [duplicate]
I'm making some header files that I'll be using, so far I have 4, which are named: name.h patrons.h library.h and book.h. My problem is this: library.h contains a book object which is found in the ...
0
votes
1answer
31 views
When might functional programming not be the best approach over object orientation? [on hold]
Let's say you're me and you have a large body of C code to maintain, part of which looks like this:
void DoSomethingInteresting(SomeType type, SomeThing thing, SomeValue value) {
switch (type) {
...
1
vote
2answers
30 views
Pass value to caller without using `return`
I have a following two functions where, I need to set a boolean value in second function but I need to use that value later in the calling function.
Restrictions:
I cannot return the boolean value ...
0
votes
0answers
22 views
jQuery extend multiple objects with the same function
So I'm using $.extend to combine multiple components (objects). Some of these components have a function with the same key. I want the final extended object to have that same key, but have it point ...
0
votes
2answers
28 views
Accesing private static properties via Closures - is it rational?
I intend to create classes that contain pure immutable data, and simple trait (or class, it's not the point) to access it. So, dummy code to illustrate what I mean:
//Data class
class DataStorage
{
...
-4
votes
1answer
38 views
Why give this error message? [on hold]
I'm very beginner in php..so that I don't understand why give this error message?
Please help me. This is my first question in this site.
<?php
class shatil{
var $sat;
function ...
0
votes
3answers
70 views
Declaring object Foo inside Foo? [duplicate]
to start of let me just explain what i am trying to accomplish here, basicly im doing some basic pathfinding in a game, and for this i have constructed a very simple class called Node and inside of ...
0
votes
0answers
25 views
Php OOP Class Extensions
I have 3 main classes that i use throughout my application. They are also used in every other class that i create. I am new to PDO i am trying to avoid using these classes by passing them as ...
0
votes
2answers
17 views
Can we create custom logs files in Sugar CRM through its own methods?
Actually I work on a Sugar CRM package which is for Sugar On Demand.
In this package Sugar CRM On Demand does not allow file handling PHP functions But I want to create separate log files for my ...
3
votes
1answer
53 views
OO Right Pattern
Two developers have a dispute on which pattern is the right one. I would be very happy if someone could tell me who is right and why.
Developer 1:
class a has two functions:
Remove(int item);
...
0
votes
1answer
58 views
How can I get rid of an instance once and for all?
I have an instance of an object - how can I get rid of it?
Imagine this:
item1 = new MyItem( 123, "Test Item", "I am a test item" );
item2 = item3 = item1;
item1 = null;
I create an instance of ...
0
votes
0answers
17 views
Does this PODS refactored code violate Encapsulation?
I wrote a class as follows:
public class Foo{
public int p1;
public string p2;
public string p3;
public string p4;
public Foo(int p1, string p2, string p3, string p4) {
this.p1 = p1;
...
1
vote
2answers
31 views
OOP design suggestion for inheritance
abstract class db{
// return an handle to db
}
class type extends db{
// code that uses db
}
abstract class limits extends db{
// code that DOES NOT use db
}
class otherclass extends ...
0
votes
2answers
25 views
override main class static function in php
I have a class as below:
class Base {
public static function test() {
echo "A";
}
}
Now i want to create new class with extending it with Base class so that i can override base class ...
0
votes
1answer
43 views
Understanding Interfaces and Abstract Classes
I have never used Interfaces or Abstract Classes in PHP, but have come to a point where I want to support similar but different types of the same object (in this case Network Switches) and possibly ...
0
votes
0answers
10 views
Default value in class attribute or in constructor? [duplicate]
I'm drawing a bit of a blank with what the difference is between setting default attribute values in their definition vs initializing them in the constructor?
Setting default in attribute...
class ...
0
votes
1answer
10 views
OOP organization with a Map
I have a question about organizing code while also displaying fundamental OOP principles. My task is to implement a world (MxN grid) with robots who get instructions to move around in the form of ...
4
votes
5answers
44 views
How to modify method return value in all derived classes?
Imagine you have a class hierarchy as:
class Base
{
public virtual string GetName()
{
return "BaseName";
}
}
class Derived1 : Base
{
public override string GetName()
{
...
1
vote
6answers
72 views
Instanceof correct usage in java
Instance of is considered to be a bad practice in java. But I don't know how to avoid it in such situation.
Let's say I have an abstract class ArtObject and there are some subclasses such as Painting, ...
-3
votes
1answer
54 views
Assigning default values for parameters
I'm studying Javascript and I found a problem. I must define the constructor given some parameters. I insert them but I wanted to insert an if to check when the user inserts nothing. I'm working with ...
0
votes
1answer
27 views
Why might variables in a class be required to be static?
I am attempting to adapt the Amazon Simple Pay Standard PHP library for dynamic use. It was written to be a button factory of sorts. The primary section of code that I have found need to edit is the ...
-1
votes
1answer
26 views
Javascript event addEventListener registering multiple times for same function; using OOP Javascript
I'm employing Object-Oriented Javascript, in conjunction with registering event listeners. From what I understand about event listeners, if the function applied to eventtarget has already been ...
0
votes
1answer
42 views
Updating object `A` when object `B` is changed - Android programming
I have two classes that hold a bunch of data that the user inputs and specifies.
Class A has several parameters, and one of it's parameters is it gets assigned an instance of class B.
Now, both ...
0
votes
0answers
19 views
Got LNK2001 error [duplicate]
I got 3 error:
error LNK2001: unresolved external symbol "private: static class std::basic_string,class std::allocator > * CDiceGame::diceInfo" ...
0
votes
5answers
36 views
Enforce method execution order in Abstract Class
I have a business case in which 3 things need to happen, in sequence:
download()
process()
upload()
Now, the Abstract Class FileTransfer provides implementation for 1. downloadFiles() and 3. ...
0
votes
1answer
19 views
PHP: What's the best way to type hint a class in an inherited method from a concrete class' parent class?
Yeah I know, that title is a mouthful :)
Code will make this way more digestible:
namespace AbstractLevel;
abstract class Bar
{
public function addFoo(Foo $foo)
{
...
0
votes
2answers
25 views
C# Event Call Back in interface
In my C# library I have an interface which exposes set of method to the consuming class.
Now my class need to raise some events. I was thinking to embed the event definition in my interface only so ...
0
votes
1answer
17 views
Having PDO::fetch(PDO::FETCH_CLASS) return a null-valued instance of the object instead of a bool(false)
My users manage the clients of the company via a web interface. They can navigate to clients using (amongst otherways) an input to directly choose a client id, which will show them the client entry.
...
-2
votes
0answers
25 views
Need an advice on web app architecture on Cogeigniter [on hold]
I read documentation on Codeigniter and i couldn't find any information on how I need to build my app in Codeigniter way. I also read some forums and all I got is "Make an app like you want to". But I ...
14
votes
15answers
980 views
What is more important, testability of code, or adherence to OOP principles? [closed]
My teams evolution of TDD includes what appear to be departures from traditional oop.
Moving away from classes that are self sufficient
We still encapsulate data where appropriate. But in order to ...
223
votes
19answers
84k views
Why Doesn't C# Allow Static Methods to Implement an Interface?
Why was C# designed this way?
As I understand it, an interface only describes behaviour, and serves the purpose of describing a contractual obligation for classes implementing the interface that ...
22
votes
4answers
7k views
What exactly is the singleton class in ruby?
It seems as if I'm missing the point or misunderstanding the significance of the singleton class in Ruby. I've heard and read it in many ways—some more complicated than others—and left more confused ...
183
votes
13answers
39k views
What is the Liskov Substitution Principle?
I have heard that the Liskov Substitution Principle (LSP) is a fundamental principle of object oriented design. What is it and what are some examples of its use?