oop

How to encapsulate the helper functions(commonly used apis) in a OOP language like java?

These functions may be hard to fit into a specific class, what's the best practice to deal with them? ...

Hash Tables - Java

Am about to do a homework, and i need to store quite a lot of information (Dictionary) in a data structure of my choice. I heard people in my classroom saying hash-tables are the way to go. How come? ...

What is the use of reflection in Java/C# etc

I was just curious, why should we use reflection in the first place? // Without reflection Foo foo = new Foo(); foo.hello(); // With reflection Class cls = Class.forName("Foo"); Object foo = cls.newInstance(); Method method = cls.getMethod("hello", null); method.invoke(foo, null); We can simply create an object and call the class's m...

Learning OOP Design

I've read Head First Java, and I understand how OOP works. Here's my problem: I'm a PHP programmer, and while I've used OOP in PHP, I'm having trouble figuring out what should be an object and what methods to give it. For example, let's say I have a app that allows people to log in and edit a document. Why should the document be an obje...

Gravity Sort : Is this possible programatically?

Hi, I've been thinking recently on using the Object Oriented design in the sorting algorithm. However I was not able to find a proper way to even come closer in making this sorting algorithm that does the sorting in O(n) time. Ok, here is what I've been thinking for a week. I have a set of input data. I will assign a mass to each of t...

PHP OOP question about reference

Can one please explain with example what does $obj->$a()->$b mean? I've used PHP OOP quite a long time and have seen in some places this structure and not just this $obj->$a(); In what cases should I use it? Thanks in advance! ...

What's the most used philosophy of keeping independent concepts separate in OOP?

Or according to your own experience, what's your favorite trick ? ...

PHP: Get instance of static class by string value

I'm working on a php web api that was handed to me with a lot of code that needs to be refactored. The ones that wrote the code wanted to include a static configuration class to an api resource and then get an instance of that class something like this: <?php $obj = "User"; $confObjectSuffix = "_conf"; $confObject = $obj.$confObjectSuff...

Implementing Domain Driven Design

Is anyone using the techniques from Domain Driven Design? I've recently read the Eric Evans book of the same name (well, most of it!) and would be interested to hear from anyone who's implemented all/some of it in a project (particularly in C#/C++) I've kept this question open ended as I'd like to see as many comments as possible, but I...

Mutable class as a child of an immutable class

I want to have immutable Java objects like this (strongly simplyfied): class Immutable { protected String name; public Immutable(String name) { this.name = name; } public String getName() { return name; } } In some cases the object should not only be readable but mutable, so I could add mutabili...

How do I extend in my class a Dom element, in mootools

I want to create a Class, say MyDiv, which inherits from the original DOM DIV element. Later in my code I would like to use it like that: $('a-container').adopt(new MyDiv('my own set of params')); I am missing the exact syntax to do it. ...

What is a Windows scripting language that: does not rely on .NET and offers the most OOP support and has simplest deployment?

What is a Windows scripting language that: does not rely on .NET and offers the most OOP support and has simplest deployment? It doesn't necessarily need to be a scripting language; It can be in the form of a compiled executable, however it needs to be self contained--only ONE file, no DLL's and it cannot be declared to "include" other ...

Error code while trying to use private variables in a function

I get an error that says Parse error: syntax error, unexpected T_PRIVATE in E:\PortableApps\xampp\htdocs\SN\AC\ACclass.php on line 6 while trying to run my script. I'm new to classes in PHP and was wondering if someone could point out my error. Here's the code for that part. <?php class ac { public function authenticati...

Passing pointer position to an object in Java.

I've got a JPanel class called Board with a static subclass, MouseHanlder, which tracks the mouse position along the appropriate listener in Board. My Board class has fields pointerX and pointerY. How do i pass the e.getX() and e.getY() from the MouseHandler subclass to its super class JPanel? I tried with getters, setters, super, and c...

"Closures are poor man's objects and vice versa" - What does this mean?

Closures are poor man's objects and vice versa. I have seen this statement at many places on the web (including SO) but I don't quite understand what it means. Could someone please explain what it exactly means? If possible, please include examples in your answer. Thanks. ...

A PHP design pattern for the model part [PHP Zend Framework]

I have a PHP MVC application using Zend Framework. As presented in the quickstart, I use 3 layers for the model part : Model (business logic) Data mapper Table data gateway (or data access object, i.e. one class per SQL table) The model is UML designed and totally independent of the DB. My problem is : I can't have multiple instance...

Generic overloading tells me this is the same function. Not agree.

base class: Class List(Of T) Function Contains(ByVal value As T) As Boolean derived class: Class Bar : List(Of Exception) ' Exception type as example ' Function Contains(Of U)(ByVal value As U) As Boolean compiler tells me that that two are the same, so I need to declare Overloads/new this second function. But I want use U...

Can a problem have a relation of aggregation and composition both between two classes at same point of time?

Can a problem have a relation of both aggregation and composition between two classes at the same point in time? Like any real time scenario where there can be aggregation corresponding to one method and composition related to other method. I am unable to figure out any scenario where both composition and aggregation occur simultaneous...

Is a switch statement the fastest way to implement operator interpretation in Java

Is a switch statement the fastest way to implement operator interpretation in Java public boolean accept(final int op, int x, int val) { switch (op) { case OP_EQUAL: return x == val; case OP_BIGGER: return x > val; case OP_SMALLER: return x < val; default: r...

Unable to compare valuesfrom mysql in a prepared statement

I can't seem to get this to connect to the database so that I can run my prepared statement. Does anybody have an idea what I've forgotten? private function check_credentials($plain_username, $password) { global $dbcon; $ac = new ac(); $ac->dbconnect(); $userid = $dbcon->prepare('SELECT id FROM users WHERE username ...