oop

C# OO design problem with override from methods

Situation: Assembly 1 ________________________ ________________________ | Class A | | Class B | |-----------------------| |-----------------------| | Method someMethod |---------->| Method otherMethod | | | | | |_____...

OOP best practice: Employee.GetCars() vs Cars.GetByEmployee()

Given the classes Company, Employee, and Car what is the preferred practice for methods to retrieve Cars associated with Company or Employee? Employee.GetCars(params...) Company.GetCars(params...) Or: Cars.GetByEmployee(params...) Cars.GetByCompany(params...) The first approach is the one I have generally used and always seemed the...

JS: related objects

Scenario: - fill object1 - copying the content of object1 to object2 - delete element from object1 Result now: - both object1 and object2 have 1 element deleted...?! Wished result: - object1 should have 1 element less than object2 The code: var object1 = new Object(); object1['key_one'] = 'value_1'; object1['key_two'] = 'val...

Indirectly destroying object from it's own virtual method. Is it a defined behavior?

Am I allowed to indirectly destroy object from within object's own virtual method? Is it a "defined behavior" (as long as I'm not trying to access anything after destroying the object)? Example: #include <memory> #include <stdio.h> using std::tr1::shared_ptr; struct Child{ virtual void selfdestruct() = 0; virtual ~Child(){ ...

Refactoring a large class

Hello, I'm importing products and so I have an product import class. It has around 4000 lines so I want to break it up. I've started to break it up but I have difficulty deciding what should be a class and what should not. I think all my methods use three of the same instance variables, so if I separated the methods, I would be passing ...

Large Class Refactor Rules

Hello, This is another question related to a question I asked a few minutes ago. If I have a class that I believe only has one responsibility but a lot of business rules and that class is large, about 4000 lines or more, is it OK to not re-factor the class into multiple classes. ...

Using $this when not in object context error

Hello, I'm getting a fatal PHP error when trying to execute my script: Using $this when not in object context The script collects data from Google Analytics via API, then displays it on a page. Below is the piece of code where the script dies: $records = $this->getAnalyticRecords ( date ( 'Y-m-d', $startTime ), date ( 'Y-m-d', $endEnd ...

Access $classA from $classB when $classB is called from $classA->__construct()

I think my title about says it all. During the __construct()-tion of $classA, $classB is instantiated. When $classB is instantiated it needs to access to another class inside $classA (i.e. $classA->classC). $classC has already been instantiated in $classA. Inside the __construct() function of $classB I am attempting to do something like...

Multiple inheritance in C#

Hi All, As I am working as a C# developer, I know that we can implement multiple inheritance by use of Interface. Can anybody please provide me link OR code for how to achieve multiple inheritance with C#. I want code for how to achieve multiple inheritance in C# with the use of Interface. Thanks in advance. ...

Advise requested regarding proper use of encapsulation in Java

I'm creating a little puzzle game just as a hobby project but the project has now reached a point that there is quite a lot of code (about 1500 lines). Although I've tried to prevent it, the code has become messy. I definitely want to clean up the code and make it more maintainable and readable while I still can. There are 3 classes han...

Validating a form for email exploits is not working

Hello, I have a contact form in my website. I made a class to handle the whole process. But there is something not working in it. I have 2 functions to check for exploitation and they are not working. I don't know what's wrong with them, so here they are : private function _validateExploit($val) { $exploitPattrens = array('conten...

How can I refactor/extend the following model

I currently have a cache implementation (using arrays) for the heavy computations performed during the simulation. The structure of the cache is as follows: The way it works: CalculationsAbstract calculationsCache = new CalculationsCache(); // Constructor of CalculationsCache public CalculationsCache() { this.Proxy = new Calculat...

How to create a jQuery element cache mechanism?

I think I wrote a simple DOM cache mechanism to be more efficient, avoiding multiple $('blah') calls, e.g.: if ($('foo').length) { $('foo').bar(); } So I created a DomCache child object under my project main object: MyLib.DomCache = {}; When I need a jQuery object of an element, I look in the DomCache and if I found it I use it...

Emulate public/private properties with __get() and __set()?

I was writing a class that uses __get() and __set() to store and retrieve array elements in a master array. I had a check to make some elements ungettable, basically to re-create private properties. I noticed that it seemed that __get intercepts all calls to class properties. This sucks for me, because I wanted to have a variable priva...

Accessing the same function from two different classes

Hi. I have two classes, suppose A and B. Within B, I instantiate A. I have a function func() that is required by both the classes. How should I go about it? I had thought of this approach: class A: func() class B: x = A() func() def func(): And then I can access func() from within A or B. Is this approach OK or is ther...

passing parameters from constructor to functions in processing/java

I'm having trouble with some objects in processing. the code should have two objects displayed and moving. but i only see one object displayed and moving. maybe there's something i'm missing. check out the code. Rule myRule; Rule myRule1; void setup() { size(200,200); smooth(); //Initialize rule objects myRule = new Rule(0,100...

How do you handle complex data structures (OOP) in a mySQL DB?

I'll try to illustrate what I mean with an example. Say you are running a site that has users and allows posts. You have a list of users and each user has: a name a password choice of theme POSTS: - title of post - time/date of posting - post ID - array of tags for the post User ID/name/pass/theme is easy. Each variable can be a c...

dynamic object creation php, creating object from param problem

Hi, So Im trying to make an object dynamically, please see below code from my item model function get_total($param) { $i = new Item(); $items = $i->get(); $total_value = 0; $query = "$item->".$param; foreach($items as $item) { if($item->qty > 0) { $total_value += $query * $item->qty;...

Implementation question of the Presenter in MVP

So..I intend to use a Model View Presenter(the "passive" mode, in which the UI is pretty dumb and sends all the events to the Presenter, and the Presenter takes care of dealing with the Model) to glue my domain's business logic and the UI. My question is how should my Presenter look like. Is this what I want? public class TicTacToeGame...

What type is "new { id = 0 }" in C#?

I'm using var abc = new { id = 0 }; in my C# code without knowing what type it exactly is! Is is simply called an object? Is it a particular type of object? I want to know coz I don't know how to add fields to this kind of object Quick example: I have var abc = new { id = 0 }; and I want to add to abc the field name = "david" ...