// refactoringmotherfucker.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。//#include<iostream>#include<vector>#include<memory>// before refactoring of split loopclassPeople{public:People(double _age,double _salary):age(_age),salary(_salary){}double age;double salary;};classBeforeApplication{public:voiddoWork(){init();printValues();}voidinit(){
peoples_.push_back(std::make_shared<People>(23,8000));
peoples_.push_back(std::make_shared<People>(25,13000));
peoples_.push_back(std::make_shared<People>(30,15000));}voidprintValues(){double averageAge =0;double totalSalary =0;for(int i =0; i < peoples_.size(); i++){
averageAge += peoples_.at(i)->age;
totalSalary += peoples_.at(i)->salary;}
averageAge = averageAge / peoples_.size();
std::cout <<"the average age is: "<< averageAge << std::endl;
std::cout <<"the total salary is: "<< totalSalary << std::endl;}private:
std::vector<std::shared_ptr<People>> peoples_;};// after refactoring of split loopclassAfterApplication{public:voiddoWork(){init();printValues();}voidinit(){
peoples_.push_back(std::make_shared<People>(23,8000));
peoples_.push_back(std::make_shared<People>(25,13000));
peoples_.push_back(std::make_shared<People>(30,15000));}voidprintValues(){
std::cout <<"the average age is: "<<averageAge()<< std::endl;
std::cout <<"the total salary is: "<<totalSalary()<< std::endl;}doubleaverageAge(){double result =0;for(int i =0; i < peoples_.size(); i++){
result += peoples_[i]->age;}return result / peoples_.size();}doubletotalSalary(){double result =0;for(int i =0; i < peoples_.size(); i++){
result += peoples_[i]->salary;}return result;}private:
std::vector<std::shared_ptr<People>> peoples_;};intmain(){// refactoring before
std::shared_ptr<BeforeApplication> before_app = std::make_shared<BeforeApplication>();
before_app->doWork();// refactoring after
std::shared_ptr<AfterApplication> after_app = std::make_shared<AfterApplication>();
after_app->doWork();}
Spring Spring IoC注解式开发为什么使用注解Spring注解的使用Value注解Autowired注解全注解式开发 Spring IoC注解式开发
为什么使用注解
注解的存在主要是为了简化XML的配置,注解的开发能大大提高我们的开发效率的,但它在一定程度上违背了OCP原则。
…
var dates {//定义的对象year:now.getFullYear(),month:now.getMonth()1,date:now.getDate(),hour:now.getHours(),minute:now.getMinutes(),second:now.getSeconds()
}//开始遍历循环
var val;
for (val in dates){console.log(对象名称:val-对象的值:…