Tag Info

New answers tagged

1

If you need examples when to bind data and behavior and when to separate, patterns books like GoF do have them. Important part: every pattern has a well-defined applicability area, telling when to use it. Another basic design principle is "Low coupling (between entities), high cohesion (inside single entity)", the entities being objects or functions or pure ...


3

I would do this: For every class that implements IContextMenu create a Factory/Creator. For example for a class named TypeAContextMenu create a TypeAContextMenuCreator, for TypeBContextMenu create a TypeBContextMenuCreator, etc. Every creator implements the same interface, like say IContextMenuCreator, they just have a create() method that returns an ...


8

The main purposes of OOP is to limit scope in which fields (or properties) can be mutated. This makes reasoning and debugging of said code much easier. That is why 3rd question you are referencing talks about mutability. If your fields are immutable, then there is no need to limit scope of access to field, so separating data from operations makes much more ...


4

The easy answer is to mix data with functions that are responsible for that data. For instance, if you have a Document class, it makes sense to have a CalculateWordCount function in it, since it's the class that's responsible for the Words inside the Document. Alternately, you can have the Document responsible for Paragraph objects, which are in turn ...


0

If your conclusion from previous answers is that you should separate function fron data, either You have misunderstood the answers Those answers are wrong. This assumes that you are using an object oriented language, where the whole idea is to combine functions and data.


1

Yes. There is always a way to do this as you can always keep piling abstractions on top of each other. For example, you can combine a mapper and a repository into a service class. Or you can split a single class with different calls to the REST API into a separate class per call. The real question is not if you can but if you should. Does your application ...



Top 50 recent answers are included