oop

in .net, if a function returns an object, is it wrong to just use the function, _as_ an object?

I've got a f(x) that returns a collection of user controls. .Net lets me just treat the f(x) name as the collection. Is there something wrong with doing so? ex) Private Function GetCcB() As Collection(Of Reports_ucColumn) Dim cc As New Collection(Of Reports_ucColumn) cc.Add(Me.ucColumn0) cc.Add(Me.ucColumn1) cc.Add(Me...

Using empty parent class just to group other classes. Is there a better approach?

I have several classes that conceptually belong to one tier. They have no common properties which is why they have no need to inherit from some base class. I also have a few methods that deal with these classes. Some of them are templates of the following style: public SomeClass { public void SomeMethod<T> (T argument) where T : Ba...

Aggregate Objects

If you have a class A that is an aggregate of class B and C, is it better for A to store ID's for B and C to load and store the entire object for B and C (edit, store by reference to object B/C, i.e. instantiate objects B and C as opposed to storing id's for B and C. store the ID's and provide methods to pull methods B and C I'm assu...

Is it really that wrong not using setters and getters?

I'm kind of new in PHP. For some reason in other types of programming languages like JAVA I have no problem with using setters and getters for every single variable, but when I'm programming in PHP probably because it is so flexible it feels kind of like a waste of time. It feels simpler to just set the class attributes as public most of...

Getting database values into objects

The thing is that you have classes and then you have the database data. When you create an object how do you set the objects properties to contain the data in the database ? I saw something like this and I'm wondering if this is really the best way to do it. I'm sure this is a fairly common issue, but I don't know what are the most acce...

PHP Listing Dynamic Member Variables

How would I list all the public variables in an instantiated Object given that we do not know the variable names in the first place? Scenario A class may have a function declared like: function addVar($name, $val) { $this->$name = $val; } I want a list of $names that were ever added to the object instance dynamically. ...

When exactly does a method have side effects?

As I always understood it, any change to the programs state (or anything to do with IO) is a side effect. It does not matter, whether the change occurs in a global variable or in a private field of the object the method is called on. It follows that all methods which do not return anything either do nothing at all or have a side effect. ...

Is DDD a waste of time?

Googling "What kind of applications is DDD suitable for?" gave me the following answer: Probably 95% of all software applications fall into the “not so good for using DDD” categories. (see the article) So what is all the fuss about?!? The application I am working on is mainly data-centric but still contains some business logic an...

Can Procedural Programming use Objects?

I have seen a number of different topics on StackOverFlow discussing the differences between Procedural and Object-Oriented Programming. The question is: If the program uses an object can it still be considered procedural? ...

How to design my classes to leverege factory and be extensible?

My c++ SOA app has a concept of "session" that is used exchange data between services. In example its used for checking legality of some service A operations before executing session B which commits or rollback changes. Whatever. I have 2 types of session modes: normal and what-if. Going further, I have different session, session for le...

Property is null, even after being set in code.

Hello, I've been trying to solve this for ages (3 days) now and I just cannot figure it out. I will try to explain the problem comprehensively because it is a bit more complex. My school assignement is to create a simple text game using OOP in C# Visual Studio 2008 (should be built on a library the teacher provided for us). It should o...

What should I do with an object that should no longer be used in Perl?

I am writing a class that is linked to an external resource. One of the methods is a delete method that destroys the external resource. No further method calls should be made on that object. I was thinking of setting a flag and die'ing inside of all of the methods if the flag is set, but is there a better, easier way? Something invol...

How can I construct an object using an array of values for parameters, rather than listing them out, in JavaScript?

Is this possible? I am creating a single base factory function to drive factories of different types (but have some similarities) and I want to be able to pass arguments as an array to the base factory which then possibly creates an instance of a new object populating the arguments of the constructor of the relevant class via an array. ...

DRY vs. "prefer containment over inheritance"

There is a general rule of OO design that you should model is-a relationships using inheritance and has-a relationships using containment/aggregation and forwarding/delegation. This is further narrowed by the admonishment from the GoF that you should generally favor containment over inheritance, suggesting, perhaps, that if you could mak...

Why is Self assignable in Delphi?

This code in a GUI application compiles and runs: procedure TForm1.Button1Click(Sender: TObject); begin Self := TForm1.Create(Owner); end; (tested with Delphi 6 and 2009) why is Self writable and not read-only? in which situations could this be useful? Edit: is this also possible in Delphi Prism? (I think yes it is, see here) ...

How to handle different processing based on message type?

I have a process which has a "notify" method which receives as a parameter the base class of the message type. I'd like to do different processing based on the derived type of message. Does this mean I need to add a method called "process" or something similar to the message type, and invoke it using polymorphism? Is it better to add a "...

Connecting modules with in an application.

While working on my hobby projects i split code in to background operations and gui operations. So i end up having library objects that does the actual work and gui objects that represent menus, frames and such. The thing that bugs me every time is that i end up having lots of objects that has to know about other objects. Such as toolba...

Is object composition without dependency injection a bad thing?

When unit-testing objects which have a composition relationship with another object (a "has-a" relationship), as I understand it, you can only really mock the composed objects if you are using dependency injection of some sort. Hence, code of the following kind make unit-testing very difficult and might therefore be considered a bad thi...

prototype based vs. class based inheritance

In javascript, every object is at the same time instance and class. To do inheritance, you can use any object instance as a prototype. In python, C++, etc.. there are classes, and instances, as separate concepts. In order to do inheritance, you have to use the base class to create a new class, which can then be used to produce derived i...

Architectural considerations in designing console applications?

I have recently programmed a console application and I've experienced a lot of pain in designing it in many aspects, particularly in C#, given its pure OO paradigm. Questions I have faced include anything from how to pass the options to how to return problems to the entry point class, among many, many others. My question is: would any o...