A
A
Alexey Nikolaev2015-11-30 15:28:35
PHP
Alexey Nikolaev, 2015-11-30 15:28:35

What is better to use when there is no difference in technical terms - static methods or class instances?

Good afternoon.
We are talking about, for example, models that contain only self-sufficient functions that do not contact each other in any way, or libraries of functions. Create a new instance before calling, or just make all methods static - wouldn't the latter be faster and better? In architectural terms, there is no difference, because. the two approaches are interchangeable in this case .
Thanks in advance for your advice!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
OnYourLips, 2015-11-30
@Heian

In architectural terms, there is no difference, because. the two approaches are interchangeable in this case.

This is not true. Static classes are evil.
A huge disadvantage of static classes is tight cohesion.
This masks the dependencies.
This forces you to change the code instead of providing an object of the same type (but different).
This complicates the tests.
It is a "global variable" among classes.
Reason enough?

M
Mikhail Osher, 2015-11-30
@miraage

Read (don't skim, just read) Martin's Clean Code, McConnell's Perfect Code, Gang of Four Design Patterns.
Then you stop asking such dubious questions.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question