Tag Info

New answers tagged

0

It's not clear to me if you're following an OO methodology that uses analysis first. That way, you first have classes that represent only the problem domain. Then you consider the same software classes, but you're allowed to deviate from that. getSchedule() could be a method in a so-called Use-case Controller also know as Front Controller which can be seen ...


1

Your best bet is to first learn JavaScript without any frameworks. It works both in the client and server side (as Node.js). JavaScript is Event Driven by itself so you won't face much issue here. Since you are coming from a C# background and your team uses PHP, I would highly recommend the Dojo Framework. It works both on the client and server side or it ...


0

I see you need a solution for both the UI and the server. As far as event driven web development is concerned, you may try the EXTJS by Sencha. It a javascript based framework,standardized and one of the most preferred. The best feature,which is the best according to me, is it can communicate with your server in variety of formats like the widely used XML ...


0

I would usually keep the collaborator objects as pointer members in the object that will use them. I would also usually have them implemented using an abstract class and pass the pointers as parameters to Shop's constructor rather than having Shop building them itself. This decouples Shop from the detail of how products are loaded, and means I can change to ...


0

There are a very wide variety of web frameworks in different languages, and in considering them it is always worth bearing in mind that in reality there is only a single type of event in server-side web development (the browser requested to load some data). That said, there are some frameworks that attempt to emulate a system where the server responds to ...


1

The subject you're asking about is called modeling, and it's as much an art as a science. But the first step of OO modeling is to forget about the mechanics of the language and think about the properties of the things you're modeling. A class named ProductsLoader is suspect to begin with. Names like that indicate that you're thinking procedurally instead ...


1

At a general level, the method needs to go with the object that has responsibility for the function. Based upon your domain, the Student has the responsibility to provide a GetSchedule() method, as the Student owns the courses that it is taking. And while the Parent may have a requirement to be able to see the Students schedule, the responsibility to ...


1

As said in the comments on the OP, I don't think an interfacing class class makes sense in this instance since there is a direct relationship between Students and Parents. Think about the relationships of the concepts outside of the system. Does every student have a schedule? By my limited knowledge I'd say it sounds like it. It also sounds like you'll ...


5

Primary reason to use a class is that there is a concept in domain you are trying to express in your code and you want to codify this concept in some way. Usually, classes are created when you, as a developer, see, through your years of experience, that there is a concept in what you are trying to achieve and you want to explicitly convert this concept into ...


-4

Simple: static classes are exceedingly dumb. If you think you have identified a case for a static class, then stop- because you haven't. You may have identified a namespace. There are no static classes in OOP.


3

In OOA&D I would like to know how you easily distinguish if a class is non-static? Why? In OO, static classes should be very rare (if your language allows them at all). Your IDE will quickly tell you that there is no constructor for that class, and if not your IDE, the compiler surely will. But for the one who is used to procedural programming ...


0

I concluded it as this to myself: Non-static class is a class which has at least one variable that its value varies among its instances. (However instances of a class might have some varied behavior without any member variable but we talk about the most common classes). Then It often possess one or more related variables of your project as instance ...


-2

Most of the time your classes will represent entities (tables) from your database. This will make it much easier to work with that data and working with data is 90% of what applications do. With classes the data is well structured in your code. So a programmer will be able to see the big picture (what the application is all about) just by looking at the ...


2

You don't need a class for that, but maybe you want one. At the database design level, I like to avoid linking tables and think of those tables as first class entities instead. So if we have student and class tables for example, instead of creating a student_class linking table to satisfy that many-to-many relationship, we could call it something like ...


1

That is correct. You simply have a property of groups (which makes more sense to me than students, but that's a matter of opinion) that is an enumerable collection of students that belong to the group.


1

In .net specifically, properties originate from the old Visual Basic days which as it happens was not object oriented in the way we think about it today. It was largely build around the then-new COM system that superficially treated everything not necessarily as classes but in terms of components which would expose properties that could be accessed both in ...


2

It's a matter of implementation versus implication. Properties were in OOP before C++ or Java hit the scene (they were there, with some roughness around the edges, in Simula, and they are fundamental to Smalltalk). Entities with properties are conceptually different from values with code attached. The get & set prefixes in some language conventions only ...


4

It's all about Encapsulation and the Uniform Access Principle. An object should be able to respond to a message by either returning existing data or running a method, but the sender shouldn't be able to tell which is which. Or if you view this from the sender's side: the sender should be able to access existing data or run a method through a uniform ...


9

You have it backwards (kind of). Lambda Calculus exists as pretty much the core formal basis for programming languages, and has been for decades. It has no fields. To model mutable state, you need to make two abstractions. One represents setting some state, and another that retrieves that state (Chapter 13 in my version of TaPL for reference). Sound ...


17

Well, I am not 100% sure, but I guess things are probably simpler than you expect. From the OO modeling schools of the 90's, there was a demand for modeling classes with encapsulated member attributes, and when implemented in languages like C++ or Java, this typically lead to code with lots of getters and setters, so a lot of "noise" code for a relatively ...


0

Absolutely nothing whatsoever. Properties and OOP have nothing to do with each other. Properties are nothing more than syntactic sugar for function calls, and therefore have exactly the same OOP-attachment that function calls do- which is to say, none. Wikipedia is completely incorrect, by the way. The getMember/setMember pattern you see in Java offers ...


3

Properties have nothing to do with object-oriented programming, because properties are only syntactic sugar. Properties look like fields superficially, and in the .net world, it is recommended that they behave like fields in some ways, but they are not fields in any sense. Properties are syntactic sugar for one or two methods: one to get a value, and one to ...


0

Interoperability is usually achieved by transferring data Generally, you can think each language being it's own separate program. This is not always the case though... Some examples: Sending sql queries to a database using json_encode() in php to encode a data structure into it's string representation, which then can be decoded by java script. Exposing ...


1

Bill Door gave some good examples where the "main program" is written in C or C++, and a scripting language is included for customization, But there is also a common, but different scenario, where the "main program", written in some "scripting language" (whatever people have in mind when they use that word) is extended by modules written in C or C++. For ...


3

Yes, it is perfectly normal to use old style code, provided the scope of your project is well known or is limited. If you plan on extending your program or project OOP is one way to go, because you can maintain and extend your code seamlessly, on the other hand if you planned it and have come to a conclusion that you are never going to plan extensibility of ...


24

C++ is not "just" an OO language, it is a multi-paradigm language. So it allows you to decide for or against OO programming, or to mix them both. Using OO techniques adds more structure to your program - from which you will benefit when your program reaches a certain size or complexity. This additional structure, however, comes for the price of additional ...


10

How do professional programmers make judgement call on whether to go for OOP or not? It would be really helpful for me. For me, there are two decision points. First, sometimes it will be obvious at the beginning. There will be lots of similar types that all share common methods that differ widely in their implementation details. For example, I was ...


4

In many cases, when you see multiple languages used together, you will find that one is a compiled language and the other is a scripting language. The compiled language is typically C/C++, but can be many other languages (Haskell, Erlang, Java, etc). The compiled language provides the base application. The base provides an interface to the underlying ...


8

Alan Kay may have created the term, but object-oriented programming didn't originate with Smalltalk; it originated with Simula, an ALGOL variant with classes and many of the concepts we consider to be core OOP principles today, including inheritance and virtual methods (polymorphism). Encapsulation (private, protected, public) was not in the original ...


4

Both Encapsulation and Polymorphism are consequences of Message Passing. (If all you can do is send a message and wait for a response, then you cannot possibly know what the receiver does to generate the response (Encapsulation) and different receiver may respond differently to the same message (Polymorphism).) Alan Kay liked Inheritance, but didn't ...


9

In a word Simplicity. When you decouple too much, you get the hello world from hell. void main(String[] args) { TextOutputFactory outputFactory = new TextOutputFactory(); OutputStream stream = outputFactory.CreateStdOutputStream(); Encoding encoding = new EncodingFactory.CreateUtf8Encoding(); stream.Encoding = encoding; SystemConstant ...


1

I'd recommended a great book JavaScript: The Good Parts by Douglas Crockford as a good guide. JavaScript AFAIK does not have (in practice) a single approach to object-orientation. Also as mentioned in previous answers it is probably more useful to learn functional paradigm mindset, unless you are going to design large frameworks like OpenLayers, jQuery or ...


12

what if; what if; what if? YAGNI Seriously. If someone wants to use different implementations of File or Math or Console then they can go through the pain of abstracting that away. Have you seen/used Java?!? The Java standard libraries are a fine example of what happens when you abstract things for the sake of abstraction. Do I really need to go ...


0

Absolutely! When I write javascript, I mainly write objects. Javascript has a wonderful, subtle, IMHO elegant object model that equates function instances, maps, and objects. So you can take advantage of each of those semantics. In practice, I end up wrapping all my code in objects, not because of my Java experience, but just because it allows for nice ...


7

JavaScript is a multiparadigm language that you can approach from a pure OOP point of view, but most people don't, for various reasons I'll describe in a bit. In my experience, idiomatic JavaScript tends to be around 50% functional, 30% OOP, and 20% procedural. However, that mix varies a lot depending on what you're doing and who you work with. Some ...


1

Javascript is more different from Java than a surface comparison might suggest. An object-oriented approach can get you a long way, but it is not in itself sufficient to become a good javascript programmer, because a few of the critical patterns of javascript are not really object-oriented in nature. You will find that judicious use of closures is as ...


1

Inbefore, these are hard decisions which need experience. And even if you are used to design software of this kind all day, you will still need time for refactoring. I can give you some advice on how to make such decision, though: Natural language Our natural languages have evolved over the time and has become quite precise to describe the things we see ...


1

In the code: Validate in the setter the collection has at least one item, and raise and exception if it doesn't. In the database: Create an episode_image table. That table would have a foreign key with the image table. Unfortunately, there's no way to enforce that for every row in the parent table, there's at least one corresponding row in the child ...


0

There are a few options: Just use a regular ICollection, document the fact that it must be non-empty, and enforce this in the setter. In the database, you would have a episode_images table. This doesn't provide the compile-time safety you're seeking, but in my opinion it's the only reasonable option. You could store a FirstImage field and a OtherImages ...


2

First you have to decide if it is sufficient to have runtime safety about the number of images or if you want to have compiletime safety. Runtime safety Achieving runtime safety is quite easy. All you have to do is remove the default setter for Images and implement a setter that performs a check before saving the given ICollection<string> argument ...


0

Is it misleading to label classes or methods as a particular design pattern (Strategy, Mediator, etc.) if they only loosely fit that definition? No, it is not misleading; rather it should not be. Too Loose Obstructs Understanding. If we say a global read only variable is a singleton, that's not "loose" that's just wrong. Besides, strictly speaking a ...


1

You're overthinking this. If your class is: public class Bill { private BillId billId; Collection<BillEntry> billHistory; } Then your Average Balance method properly belongs in the Bill class. public class Bill { private BillId billId; Collection<BillEntry> billHistory; public decimal GetAverageBalance() { ...


2

Labeling a pattern as [X] in Javadoc is really not so useful. Too many patterns are mis-applied because developers don't validate the patterns' assumptions (which are also not documented). Your Singleton example is trivial, as Singleton is more of an idiom than a design pattern. There's at least one project (http://www.jpatterns.org/) that uses Javadoc ...


-1

The underlying purpose of serialization is to ensure that data produced by one system is able to be consumed by one or more compatible systems. The easiest and most robust approach to serialization is to translate the data into a type agnostic format that maintains the structure in a simple and easy-to-consume format. For instance the most ubiquitous ...


5

Kinds of objects For purposes of our discussion, let's separate our objects into three different kinds: Business Domain logic These are the objects that get work done. They move money from one checking account to another, fulfill orders, and all of the other actions that we expect business software to take. Domain logic objects normally do not require ...


5

Is it misleading to label classes or methods as a particular design pattern (Strategy, Mediator, etc.) if they only loosely fit that definition? It depends. If you have a singleton and it does not prevent instantiation, then it would be misleading to label it a singleton, since it's not a singleton. It's a global variable. Doing otherwise leads your ...


3

if public access level method is also overridden in SubClass then public access level method has also become an implementation dependent method in every new SubClass designed, which breaks Encapsulation. Because user using public level access method addNotify(), should know that it's implementation is different in awt.Component/ awt.Checkbox/awt.Button ...


2

The answer to your last question is that it will come to you with experience. But basically, you don't start by adding new methods and then wondering which keyword to use. You start by thinking about what responsibilities the class will have, what promises it will make to the classes around it. Each class handles certain details so that other classes don't ...


6

Since you tagged this with python, I'll give you the Python perspective on this. In Python, this is entirely normal. Attributes are not private, they are merely marked as 'internal', by convention, by using a leading underscore. So _store is something that is 'internal' to the class, just as the implementation of __eq__ is an internal matter. You are not ...


1

You tagged this with object-oriented, so the answer is: no. The fact that objects only know about their own private implementation / representation and not about that of other objects even of the same type is the defining characteristic of object-oriented data abstraction as opposed to Abstract Data Types, where instances of an ADT do know about the private ...



Top 50 recent answers are included