oop

load the data of an object by method after creating, or get a instantiated object with loaded data direct?

In a webapp, i have a data-model (let's call it Item). The data of this Item is filled by two methods. The first method is a XML parser (data import), the second reads the Data from a Database (while parsing the website). I see two possible ways to implement this class: first way: public class Item() { public void parseFrom...

Class design: Access a List<T> directly or through methods?

For a newsroom system I have a class that contains a single news story. Inside this class is a private variable holding a generic List of image classes. The idea being a single story can contain multiple images. The question is should I make the List variable public, so that I can add/remove images by addressing the List directly publi...

Returning data from database in .net: Return a DataTable or LIst<T>?

I'm struggling with bridging the concepts of good database design with good object orientated design. Traditionally if I wanted to display a list of news stories in a repeater, I would use something like: <script runat="server"> void ShowNews() { rptNewsStories.DataSource = News.GetAllNews(); // Returns a DataTable r...

What is the difference between business class and domain class? What is meant by persistent classes?

What is the difference between business class and domain class? What is meant by persistent classes? ...

Self Instantiation in Java

How do I self-instantiate a Java class? I should not use any file other than its class file. Also assume that after the line where I initialized the NAME variable, they don't know the name of the class during compile-time. Example: public class Foo implements Bar { public static final String NAME = "Foo"; private void instanti...

providing abstract class member variables from a subclass

What is the 'correct' way of providing a value in an abstract class from a concrete subclass? ie, should I do this: abstract class A { private string m_Value; protected A(string value) { m_Value = value; } public string Value { get { return m_Value; } } } class B : A { B() : this("string value...

Should I use inheritance for a Ruby project involving common attributes and differing methods?

I'm learning Ruby and working on my first real project. The program will receive a data structure and needs to reproduce the information contained that structure in various text formats. All of the different output types rely on the same set underlying attributes (about 40 of them) and the same set of common functions (about 10 of them);...

Is this dependency injection in ActionScript 3?

Hi. I have a Main.fla (controlled by Main.as) that has a child named Slide (a Movieclip controlled by another class, Slide.as). Sometimes, my Slide object have to call the method "nextSlide" on his father, Main object. To do this I tried "this.parent.nextSlide()", but I got this error: 1061: Call to a possibly undefined method nextSli...

What does it mean to start a PHP function with an ampersand?

I'm using the Facebook library with this code in it: class FacebookRestClient { ... public function &users_hasAppPermission($ext_perm, $uid=null) { return $this->call_method('facebook.users.hasAppPermission', array('ext_perm' => $ext_perm, 'uid' => $uid)); } ... } What does the & at the beginning of the functi...

Inheritence to extend a data structure in Haskell

A C++ programmer trying to learn Haskell here. Please excuse this probably easy question. I want to translate a program that represents 3D shapes. In C++ I have something like: class Shape { public: std::string name; Vector3d position; }; class Sphere : public Shape { public: float radius; }; class Prism : public Shape { publ...

Propogating a "volatile" property

I put "volatile" because it's only vaguely so. I have a class which has a property called "StopRequested". This flag can be set by other threads at any time, and needs to indicate to my code that it should stop what it's doing and exit (this is a Windows Service based process, and when Stop is called, all processing needs to clean up ...

What is best approach on designing this generic abstract class? (Part 3)

Hi all Based on previous question, I've changed the context as follow: I have abstract class called Tenant and CustomerList. The Tenant in this case is like owner of the application for multi tenant application model and CustomerList is a collection of Customer class. The relationship between these 2 class are Many to One relationshi...

How to extra generic parameter after where statement?

I have an abstract class as follow: class BaseReturnType { } class DerivedReturnType : BaseReturnType { } abstract class BaseClass<T> where T : BaseReturnType { public abstract T PolymorphicMethod(); } class DerivedClass : BaseClass<DerivedReturnType> { public override DerivedReturnType Polymorp...

iPhone: Get Response From Finished Request [ASIHttpRequest]

Hello all. I am attempting to use ASIHttpRequest with the iPhone to get some information from a query-string based API on my site. Currently, I am in the planning stages of my design and I am kind of stuck on how I should proceed. I would like to have a class, that will handle all of the requests I will need. I plan on having differe...

Fatal error: Class NAME not found in (....PATH) ?

Hi What may be the problem if i get the following error. while i am extending a class i got this error example: class ModuleUser extends AbstractModule Fatal error: Class AbstractModule not found in (....PATH) ? I have done most of the possibilities... But i can't resolve the problem. any help will be thankful thanks n ad...

In a generic List<T> of objects, should I store the 'OrderID' inside each object, or just rely on the order in the list?

As the title says :) In my database the table I'm using has an OrderID field, which determines the order (strangely enough!) that the rows will be shown in when they are outputted. In the C# code this table of data is loaded in as a generic list (List) which each item in the collection being a copy of a row from the database table. So...

OOP in javascript with callbacks

I want to close my window (just a div with position absolute that is draggable) when I click on the close link This is my code function ApplicationWindow() { this.window = $('<div class="window"></div>'); this.create = function create() { //..... var closeButton = this.window.find('.close'); closeButton...

PHP/SQLite with multiple SQL statements: $db->Query() works, $this->db_sqlite->query() fails

I am creating a class that handles various SQLite actions. My problem is: When I make a SQL string with multiple statements then it works when using standard PHP => $db->query() ... but it fails when making the same request from a method. It seems that the OO method skips everything after the first ";"-symbol in my SQL statement. Why is ...

Misuse of Observer Pattern?

I have a Car object which contains a latitude field and a longitude field. I use the observer pattern so that any time either of these fields change in my application, my car object is notified. I now find the need to create several other car objects whose default values I wish to have the same as what is the current latitude and the cu...

a very simple c++ oop question

im struggling with syntax here: hopefully this question is v simple, im just miising the point. specifically, if i nest a class within another class, so for instance class a { a //the constructor { b an_instance_of_b // an instance of class b } }; class b { public: foo() { cout << "foo"; }...