oop

is an abstract class a type of interface?

In my /interfaces folder I put all my interfaces. Is an abstract class a type of interface? ...

how come in php superclasses can access protected methods of their subclasses?

I just noticed this behavior today - weird, I'm pretty sure in java a you can only access protected methods upstream on the inheritance chain since going the other way violates encapsulation. Was there a reason for this behavior in the language? ...

What is the accepted way to enforce proper value in property which depends on other properties of the same class?

Let's say I have a class which has three properties as below. public class Travel { public int MinAirportArrival { get; set; } public int MinFlightTime { get; set; } public int TotalTravelTime { get; set; } } TotalTravelTime must be at least the sum of MinAirportArrival and MinFlightTime but could also be more in the event the...

Advice writing Losely Coupled code with Agile methods or otherwise

I have been reading Robert C. Martin's (aka Uncle Bob) books very intensely as of late. I have found a lot of the things he talks about to be real life savers for me (small function size, very descriptive names for things, etc). The one problem I haven't gotten past yet is code coupling. One problem I keep having over and over is that ...

Long Operation Status

When performing a long operation in your application, how do you promote information from your business tier to your UI? Events? Passing in a status object which is hooked to the UI? Before I start I just wondered what cunning ways you guys and girls have come up with. ...

Independent MVC structure... need an advice

hi, I'm tired of looking after a frame work for mvc implementation. i want to build a good MVC based structure of my own that will serve me in my projects. so here is my thinking I'd like to know what do you think. first of all. here is the folder structure: The folder structure the Admin and the Site folders: I assume that the contro...

PHP - OOP - Storing big objects to be saved in session

I'm trying to set up a new class for my web application, rewriting my code starting from original procedural programming. Since I need to populate my object using many different(complex) queries, and this object'll be stored in session, I decided to create another static class containing all long queries. Is it more convenient to define...

shared functionality on usercontrol and form

Hi all, I need to add shared functionality to both Forms and UserControls. Since multiple inheritance isn't supported in .net I wonder how I best tackle this? The shared functionality is a dictionary that is filled by the form or usercontrol and then processed. Regards ...

Should I use, this, self or something else for self identifiers in type definitions?

My guess is that "this" is more C#-ish and in F# it's better to use "self". Are there any required/preferred coding guidelines? ...

What is the proper object relationship? (C#)

Hi, I had a quick question about the proper object relationship I should set up for this situation: I have a Customer object with associated parameters and a depot object with associated parameters. Each depot serves a set of customers and the customer needs access to particular information for their respective depot. I'm wonderin...

Is Dependency Injection Chaining an Anti-Pattern?

Here is the problem, lets say we are making a video game and want to use Dependency Injection. Here is what we have: Game Class // This is just the code to keep track of the overall game logic Character Class // This would be the guys in the game, good and bad guys both Weapon Class // The weapons for the characters So normally when ...

Is Reflection breaking the encapsulation principle?

Okay, let's say we have a class defined like public class TestClass { private string MyPrivateProperty { get; set; } // This is for testing purposes public string GetMyProperty() { return MyPrivateProperty; } } then we try: TestClass t = new TestClass { MyPrivateProperty = "test" }; Compilation fails wi...

PHP - Dealing with GET and POST arrays

In my webapp I have a page called display.php. The script in this page behaves in different ways depending on POST and GET array content/existence, let's say: If I call this page and GET array isset, the script'll load a record using $_GET['id'], in another case, if no GET isset but isset a ceratin POST key the script'll load a random re...

Any better way to tailor a library than inheritance?

Most likely an OO concept question/situation: I have a library that I use in my program with source files available. I've realized I need to tailor the library to my needs, say I need to modify the behavior of a single functions F in class C, while leaving the original library's source intact, to be able to painlessly upgrade it when ne...

Handling collection properties in a class and NHibernate entities

I was wondering what is the recommended way to expose a collection within a class and if it is any different from the way of doing that same thing when working with NHibernate entities. Let me explain... I never had a specific problem with my classes exposing collection properties like: IList<SomeObjType> MyProperty { get; set; } Hav...

Overcoming Python's limitations regarding instance methods

It seems that Python has some limitations regarding instance methods. Instance methods can't be copied. Instance methods can't be pickled. This is problematic for me, because I work on a very object-oriented project in which I reference instance methods, and there's use of both deepcopying and pickling. The pickling thing is done mos...

When should and shouldn't you break away from OOP for speed/performance?

In their developer articles for Android, Google states that you should usually declare public variables rather than private ones with getters and setters to enhance performance on embedded devices (I suppose function calls are more expensive than just writing to an address). I was wondering - to what extent should performance be sacrif...

Design pattern for adding attributes to a base class

I am sure there is a clever way to handle this, but I just can't get it right in my head. Here is the scenario: I have a base class with about 30 properties. Say that I have a property on this class called Type. For a subset of the instances of this class, I want to add a few more properties based on the Type property. In this case...

What is the difference between multiple dispatch and method overloading?

In languages like Scala, one can have multiple definitions for one method name by changing the number of parameters and/or the type of the parameters of the method. This is called method overloading. How is that different from multiple dispatch? Thank you ...

NameError: name 'self' is not defined

Why such structure class A: def __init__(self, a): self.a = a def p(self, b=self.a): print b gives an error NameError: name 'self' is not defined? ...