How to obey contract of equals() when deriving from abstract class

In his book Effective Java, Joshua Bloch writes about the pitfalls that occur with the contract of equals() when derived classes add additional fields to the check. Normally, this would break the symmetry, but Bloch states that “you can add a value component to a subclass of an abstract class without violating the equals contract”. Obviously this is true because…
Read more

PHP OOP while loop

i had a problem with looping data from mysql using OOP style. so, here is my code: class mysql { private $host; private $username; private $password; private $database; public $con; public function connect($setHost, $setUsername, $setPassword, $setDatabase) { $this->host = $setHost; $this->username = $setUsername; $this->password = $setPassword; $this->database = $setDatabase; $this->con = mysqli_connect($setHost, $setUsername, $setPassword, $setDatabase); } public function query($setQuery) {…
Read more

Concept of immutable tree

when I went through a interview question they asked “tree must be immutable”.I know immutable concept in String(java).Can any please give me the concept of immutable tree and good link also. Source: oop

$new = new self($data); with private functions and even variables oO?

I have a strange behavior in my php 5.3 i have a class wich dous this in a function $new = new self($data); $new->setServiceManager($this->service); $new->cacheInstance(); BUT the function cacheInstance is a private function…. private function cacheInstance() { foreach ($this->data as $name => $class) {…} } Can some one give an explanation why the hell can this be used like this?…
Read more

How to call an object within an object

I have this class called MAN, PUNCH and Test the PUNCH object is a field within the MAN class and everything works fine. But in the Test class, I want to access a method of the PUNCH class. How do I go about in doing this? Thanks Source: oop

Implementing generic types to a language

I want to add support for generics to a language, but before I do I need to understand more clearly what generics are inside. My current understanding is that instantiating the class: class ArrayList<T> { public int add(T $object) { // … } } Creates an instance where the argument type of T on add must be the same as…
Read more

Associating downloads to users in ASP.NET mvc

I am creating my own website and I want to be able to provide select downloads for users. Please note that I might well be misunderstanding a number of things here, so if you notice anything that doesn’t look/sound quite right please do point it out 🙂 Also, please keep in mind that the file uploads will be done via…
Read more

Weird interactions between setinterval, and classes

Working on a slider, and Ive noticed that everything works great – function Slider(element) { this.i = 0; this.element = element; var self = this; this.timer = window.setInterval(function() { switch (self.i) { case 0: $(element).velocity({ translateX: “-33.3333%” }); self.i++; break; case 1: $(element).velocity({ translateX: “-66.6666%” }); self.i++; break; case 2: $(element).velocity({ translateX: “0%” }); self.i = 0; break; } },…
Read more

Patterns for implementing HATEOAS (HAL)

I’m wondering if there are any design patterns that can be used to implement HATEOAS in a REST api. I’m thinking in java, but language independent or high level OO/functional solutions are fine. I know spring and jersey have some support for this, but I’m wondering if there aren’t some universal patterns that could be applied in any language or…
Read more