Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Object Oriented Design have a place in web development? [closed]

Tags:

oop

I work at a web development shop so naturally we deal with user profiles. When dealing with one of our sites I noticed that there was no 'User' class, which struck me as odd since we certainly have users. Instead the site relies on interacting with DataRows (this is C#) returned through static methods with little to no instantiation. I asked my boss about creating a class for users and his response was that since the objects have to be rebuilt so much its often not worth it.

I am relatively new to web development and it does seem like a bit of a waste to have to instantiate objects each time the page is rebuilt but on the other hand I've always found object oriented programming to be useful. So I'm curious for some opinions, how much do you guys use OOP in web development?

like image 277
Trajanus Avatar asked Dec 29 '09 19:12

Trajanus


People also ask

Is there OOP in web development?

Either way, it's definitely one of those web development buzzwords you should definitely know. Believe it or not, object-oriented programming (OOP for short) is nowhere near as complicated as people might have you think, and actually exists to make the task of programming easier.

Is object oriented design still used?

Five decades ago, great principles of object-oriented design and programming were defined and they can still teach us a lot today. We just have to learn and adopt them correctly. Object-oriented design is a holistic approach. It can be successfully applied to the whole span of problems in software development.

Do front end developers need to know OOP?

Is Object Oriented Programming a must for frontend development? It depends entirely on the context of the site it's being used in, but everyone should do themselves a favor and learn OOP concepts no matter what kind of development they do.

What is a open design in OOP?

Open Closed Design Principle According to tho this OOP design principle, “Classes, methods or functions should be Open for extension (new functionality) and Closed for modification”.


2 Answers

The only time I don't use OOP is when:

  1. I'm creating a simple project to test some logic. This usually leads to creating the right classes...

  2. I'm using Classic ASP (been awhile, thank god).

  3. I'm not programming.

edit 3+ years after posting the above; I'm appending a bit to my answer.

OOP is great and allows us a tremendous amount of flexibility for having multiple systems interacting with the same data / logic. However, there is certainly a situation in which you wouldn't want to bother loading up a lot of objects.. Namely, when you are simply pulling data for tabular display.

Querying a database and getting a simple record set back that is immediately emitted to the browser usually doesn't need OOP involved. As a matter of fact you might want to sidestep OOP completely as tabular data usually involves a roll up of other information (sums of child records) and you normally don't want to pull more data from the database than what you are actually using. ie. if you are only showing the name and email you probably don't want to grab the user name as that is just wasted cycles.

Now, putting information into a DB usually involves making sure that certain business logic is followed. For example that the username follows certain rules. In those situations leveraging an OOP style keeps things a bit more encapsulated and easily transferred between systems.

So, looking at the specific example: I wouldn't bother with more than handing a datatable to a repeater when pulling data; but I would have a user class for when I'm going to create a new one or operate on that user to make sure the business rules are properly followed.

like image 139
NotMe Avatar answered Oct 26 '22 03:10

NotMe


One question: does the data need to be coupled with function/method calls? If not, OOP is not necessary.

Your best approach might be to find an empty whiteboard, create a high level model using Object Oriented Design, then with Functional Design, then with Procedural. You might surprise yourself (and others) with the results. The same language can be used in vastly different ways depending on the project. As mentioned by @wj. OOP is just a paradigm, don't be afraid to step outside of your comfort zone and design using a different paradigm.

Taking time to design using different paradigms will also help you when you approach your boss to discuss why you should or should not use the current paradigm. Most bosses will appreciate that you spent the time to research before approaching them with an idea -- this isn't to say they'll accept your idea, but being knowledgable going in will potentially get you a few extra minutes of his/her attention.

IMHO (don't take this personally), "Object Oriented Programming" has fallen with the likes of "Web 2.0" -- a buzzword of sorts, which is unfortunate; you now see developers forcing OOP where it would be better suited to use FP or PP.

The best professional advice I can give is to design (high level at first, then dive down) in multiple paradigms (do your best not to be biased -- keep an open mind) and decide which one best addresses the way your application works. In my 15 years experience, 75+% of the time I find OOP to be unnecessary, although my current project is strictly OOP.

A more important/relevant question would be, "Does Object Oriented Design have a place in my current web development?"

like image 36
kmatheny Avatar answered Oct 26 '22 02:10

kmatheny