oop

Cast interface to its concrete implementation object or vice versa?

In C#, when I have an interface and several concrete implementations, can I cast the interface to a concrete type or is concrete type cast to interface? What are the rules in this case? Thanks ...

Should I always verify if an object is NULL ?

Hello, I have a object built through a factory containing my parameters read from the url. From this object, I can get the language parameter $language = $my_parameters->getLanguage(); $language is NULL if it isn't been set. $language may also be invalid ( $language->isValid() returns false ). So, to build my page, I need som...

Should enum objects be stateless?

As by design an enum constant in java is a singleton, and for sake of concurrent usage I normally create stateless enum instances and use method parameters to inject the data as needed. Example: Currently I am creating a REST service which has Operations (implemented as an enum using a variant of the strategy pattern). public enum Op...

Maintaining two versions of a business class library

Our core business application uses a library (C# project) of business objects. Data access is done using the Wilson O/R Mapper (we're migrating to NHibernate this summer). The application has 3 front-end UIs: Windows Forms, ASP.NET, and a Windows Forms app that is installed on tablet PCs. The three front-ends perform different functions ...

Is this bad oop design?

Imagine I have an interface called IVehicle. From this interface, I derive several concrete types such as bus and car (all can move, slow down, switch off engine, etc). My interface has no fields. Would it be bad design to have one class which has fields (e.g. top speed of vehicle) and use this by each of the concrete types? Would this...

Design OOP question on Decorator and Strategy pattern C#

Say for example you have a base abstract class public abstract Foo { IFlyable _fly; ISwimmable _swim; void performSwim() { _swim.swim(); } void performFly() { _fly.fly(); } } And have behaviors/algorithm that you will have in your system interface IFlyable { void fly(); } interface ISwimmable { void swim(); } in...

How do you get rid of an object in c#

In the following c# code, how do I get rid of the objects when it's no longer useful? Does it get taken care of automatically, or do I need to do something? public void Test() { object MyObject = new object(); ... code ... } ...

Do OO design principles apply to Python?

It seems like many OO discussions use Java or C# as examples (e.g. Head First Design Patterns). Do these patterns apply equally to Python? Or if I follow the design patterns, will I just end up writing Java in Python (which apparently is a very bad thing)? ...

What is the difference between class oriented and object oriented programming ?

Any interesting explanations, links, or articles so I can get a good idea? People often say things like java is class oriented, it's not totally object oriented. I have also heard similar things in interviews. I am interested in knowing if these sort of statements are true. ...

Can someone explain this OOP javascript structure

Can someone explain this OOP javascript structure? I realize it is how you create 'objects' in javascript, just need some explanation on the notation and what it means: var vote = function(){ return { P1: function() { alert('P1'); }, P2: function() { alert('P2')...

What are the main components/layers of a PHP application?

What are the main components of a PHP application? I've come up with these: 1) Database 2) HTML templates 3) Sessions/Cookies/Authentication 4) User Input ($_GET or $_POST or URL segments) Are these the main components or are there any others? The reason I'm asking this is so I can put each 'Object' in its own class without having ...

What PHP application design/design patterns do you use?

Please share your favorite application design / design patterns for use in PHP with me. Some things I'd like to know: How your folders are designed How you use object oritentation in your PHP applications Do you have a standard way of dealing with CRUD, pagination, or any other common tasks? How do you avoid using repetitive code? What...

SOLID and the user interface ?

I try to follow the SOLID principles. But every time it comes to user interfaces I find that there's an inherent friction between the clunky screenful of hybrid, aggregated data the customer requires and the nice principles of single-responsibility. Now it is possible to divide and conquer the various bits and pieces of a typical user i...

How To Handle Communication Between the Domain and Database Layers?

I am fairly new to using separate layers for the business logic (Domain) and database access logic, but in the course of working things out I've come across a problem to which I still feel I haven't found a great solution. Clarification My existing solution uses Data Mappers to deal with the database interactions directly. However, as ...

How / if to refactor a Delphi program using only forms and data modules

After years of coding Delphi programs as untestable code in forms and datamodules, including global variables, and the only classes are the forms themselves, containing all the code I need for the form UI itself. How would I convert the code to a set of classes that do the actual work? would I need to stop using the datasources/datasets...

Share variables between functions in PHP without using globals

I have a class for interacting with a memcache server. I have different functions for inserting, deleting and retrieving data. Originally each function made a call to memcache_connect(), however that was unnecessary, eg. mc->insert() mc->get() mc->delete() would make three memcache connections. I worked around this by creating a cons...

Does anyone disagree with the statement: "using switch is bad OOP style"?

I have seen it written in multiple threads/comments on stackoverflow that using switch is just bad OOP style. Personally I disagree with this. There will be many cases where you cannot add code (i.e. methods) to enum classes you want to switch on because you don't control them, perhaps they are in a 3rd-party jar file. There will be oth...

How would you refactor a "switch on Type" to be polymorphic if you don't control the types involved?

I'm writing a microformats parser in C# and am looking for some refactoring advice. This is probably the first "real" project I've attempted in C# for some time (I program almost exclusively in VB6 at my day job), so I have the feeling this question may become the first in a series ;-) Let me provide some background about what I have so...

How can you organize the code for a game to fit the MVC pattern?

Hi all, I'm a freshman in college going for my computer science degree... I've programmed plenty the last several years but just lately I've been getting more into theoretical ideas about organizing code, design patterns, differences in languages, etc. I have a Java class, so I've dropped my C++ research/development and moved into Java...

Reconciling classes, inheritance, and C callbacks

In my C++ project, I've chosen to use a C library. In my zeal to have a well-abstracted and simple design, I've ended up doing a bit of a kludge. Part of my design requirement is that I can easily support multiple APIs and libraries for a given task (due, primarily, to my requirement for cross-platform support). So, I chose to create an ...