search
HomeBackend DevelopmentPHP TutorialPHP+Java development experience: Don't be too object-oriented_PHP tutorial

Speaking of object-oriented, many languages ​​now have some. Java is a traditional object-oriented language, and PHP is also somewhat object-oriented, but not very good. In a specific project (this article is a Web development project), being completely object-oriented is sometimes not the best choice. The author of this article finally chose a model of PHP+Java and shared some of his own experiences.

I came into contact with C++ (high school) earlier and accepted object-oriented thinking earlier. Object-oriented thinking is closer to the way people think, and its features such as encapsulation and inheritance can often simplify some work. The most important thing is that the ideas look much clearer. I firmly believe in object-oriented thinking, until one day, I got confused in the WEB project.

My previous work was also related to WEB development. Usually the projects were interfaces, implementations, service layers, and DAO layers. Over time, I got used to this pattern. Later, I started to make my own website (operate it myself), and I also followed this model. It took me a while to get the thing out and it could run, and problems arose. As we all know, things like portals, especially websites in the growth stage, may often face some changes and expansions. It is not like an enterprise project or a website operating in a stable mode, where a set of written programs can be used continuously. But JAVA things are a bit troublesome to change.

First: A lot of interfaces are used in the project, and interfaces often need to be touched during business changes. Some people may say that this is because the demand is not met. Yes, you can think so, but there is a premise: the demand cannot be met in one step, otherwise the website will not run. When the demand analysis is completed, the flowers will wither. Recall this classic process: to add a feature (the page part will not be discussed for now), first add or modify a service interface; then add or modify its implementation; then if necessary, you may also add or modify a DAO layer interface, corresponding to We need to add or modify its implementation; in the end, what we really want to change is often just a SQL statement.

This series of processes is too cumbersome. The portal website basically displays information, and its business logic is basically reflected in SQL statements. Think about it, what is displayed on the website, how to sort it, how to aggregate it, don’t these all correspond to the corresponding SQL statements? If you have to write the DAO layer as basic additions, deletions and modifications, and then make a fuss in the service layer to implement the business logic that originally corresponds to a SQL statement, what's the point? Layering purely for the sake of layering? Object-oriented for the sake of object-oriented? Not to mention the pile of interfaces, which will increase the workload in vain. Of course I will not deny the significance of interfaces in programming thinking, but are the bunch of interfaces in traditional JAVA WEB programming really a reasonable application? I think in many cases it's not. I later used PHP to rewrite a large part of the functions in my project, which took only a few days, without layering or interfaces. The improvement in work efficiency brought about by this is really pleasant!

Second: The release of JAVA WEB projects usually requires restarting the service, causing WEB operation interruption. Many people are discussing hot deployment. I don’t know what level Hot Deployment will eventually reach, but I don’t think it will be able to modify files at any time and take effect at any time like PHP. In order not to interrupt the service, I usually choose to form a cluster and release in turn. Although this may still cause some problems, it is much better than interrupting the application. However, clustering will bring trouble in publishing, and the cluster itself may not be what I really need.

There are also some minor problems that come with it. For example, if my project contains some folders that store a large number of files, I have to deal with them specially when publishing, which is very uncomfortable. Even if you make a soft link, you will inevitably have to do extra work when publishing. Of course, I believe there are better solutions to these problems, and I personally am still exploring them.

Faced with the above problems, I finally stopped sticking to object-oriented. I changed the project to a pre-PHP and post-JAVA format. PHP seems to be much more flexible as a front-end. The entire revision did not take much time on the logic part of PHP, and all the time was spent on page design; the JAVA back-end can ensure stability and efficiency, and is easy to design safely. From this, I finally uttered the exclamation "Don't be too face-to-face". Demand determines everything. Following other people's thoughts is no different from joining a cult.

The problem is not over yet. For the JAVA back-end part, I am still exploring a plug-in-based CMS back-end system that can hot load and remove plug-ins. Oh, you can’t beat the person to death with a stick because of the above reasons.

But no matter what, after reading the author's description, you might as well try the combination of PHP+Java: let's see what benefits can be brought by giving up some object-oriented.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446594.htmlTechArticleSpeaking of object-oriented, many languages ​​now have some. Java is a traditional object-oriented language, and PHP also has some object-orientation, but not very good. Completely object-oriented in specific projects...
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
What are the advantages of using a database to store sessions?What are the advantages of using a database to store sessions?Apr 24, 2025 am 12:16 AM

The main advantages of using database storage sessions include persistence, scalability, and security. 1. Persistence: Even if the server restarts, the session data can remain unchanged. 2. Scalability: Applicable to distributed systems, ensuring that session data is synchronized between multiple servers. 3. Security: The database provides encrypted storage to protect sensitive information.

How do you implement custom session handling in PHP?How do you implement custom session handling in PHP?Apr 24, 2025 am 12:16 AM

Implementing custom session processing in PHP can be done by implementing the SessionHandlerInterface interface. The specific steps include: 1) Creating a class that implements SessionHandlerInterface, such as CustomSessionHandler; 2) Rewriting methods in the interface (such as open, close, read, write, destroy, gc) to define the life cycle and storage method of session data; 3) Register a custom session processor in a PHP script and start the session. This allows data to be stored in media such as MySQL and Redis to improve performance, security and scalability.

What is a session ID?What is a session ID?Apr 24, 2025 am 12:13 AM

SessionID is a mechanism used in web applications to track user session status. 1. It is a randomly generated string used to maintain user's identity information during multiple interactions between the user and the server. 2. The server generates and sends it to the client through cookies or URL parameters to help identify and associate these requests in multiple requests of the user. 3. Generation usually uses random algorithms to ensure uniqueness and unpredictability. 4. In actual development, in-memory databases such as Redis can be used to store session data to improve performance and security.

How do you handle sessions in a stateless environment (e.g., API)?How do you handle sessions in a stateless environment (e.g., API)?Apr 24, 2025 am 12:12 AM

Managing sessions in stateless environments such as APIs can be achieved by using JWT or cookies. 1. JWT is suitable for statelessness and scalability, but it is large in size when it comes to big data. 2.Cookies are more traditional and easy to implement, but they need to be configured with caution to ensure security.

How can you protect against Cross-Site Scripting (XSS) attacks related to sessions?How can you protect against Cross-Site Scripting (XSS) attacks related to sessions?Apr 23, 2025 am 12:16 AM

To protect the application from session-related XSS attacks, the following measures are required: 1. Set the HttpOnly and Secure flags to protect the session cookies. 2. Export codes for all user inputs. 3. Implement content security policy (CSP) to limit script sources. Through these policies, session-related XSS attacks can be effectively protected and user data can be ensured.

How can you optimize PHP session performance?How can you optimize PHP session performance?Apr 23, 2025 am 12:13 AM

Methods to optimize PHP session performance include: 1. Delay session start, 2. Use database to store sessions, 3. Compress session data, 4. Manage session life cycle, and 5. Implement session sharing. These strategies can significantly improve the efficiency of applications in high concurrency environments.

What is the session.gc_maxlifetime configuration setting?What is the session.gc_maxlifetime configuration setting?Apr 23, 2025 am 12:10 AM

Thesession.gc_maxlifetimesettinginPHPdeterminesthelifespanofsessiondata,setinseconds.1)It'sconfiguredinphp.iniorviaini_set().2)Abalanceisneededtoavoidperformanceissuesandunexpectedlogouts.3)PHP'sgarbagecollectionisprobabilistic,influencedbygc_probabi

How do you configure the session name in PHP?How do you configure the session name in PHP?Apr 23, 2025 am 12:08 AM

In PHP, you can use the session_name() function to configure the session name. The specific steps are as follows: 1. Use the session_name() function to set the session name, such as session_name("my_session"). 2. After setting the session name, call session_start() to start the session. Configuring session names can avoid session data conflicts between multiple applications and enhance security, but pay attention to the uniqueness, security, length and setting timing of session names.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)